Comments (5)
Ok, I was able to track down and fix this uncaught exception within my own codebase (/x/observability
). I confused it as uncatchable since it seems to be a string
instead of an Error
and thus has no stacktrace. Since my code is to instrument HTTP serving, I can now attach this exception to the request span and keep the overall server alive. Thank you two for the context!
from deno.
I looked at this again. The exception is coming from the doing things with the writer
. I think the locking needs to be tighter. The following handles the exception.
const handler = (_request: Request): Response => {
const stream = new TextEncoderStream();
setInterval(() => {
const writer = stream.writable.getWriter();
writer.write("data\n").catch((e) => {
console.log("Error: ", e);
}).finally(() => {
writer.releaseLock();
});
}, 1000);
return new Response(stream.readable, {
status: 200,
});
};
console.log(`HTTP server running. Access it at: http://localhost:8080/`);
Deno.serve({ port: 8000 }, handler);
This solution doesn't stop the interval, but I'll leave that as an exercise for the reader :).
from deno.
I'm seeing this uncatchable exception in other codebases. Am I correct in understanding that the program will crash if a client walks away while there is a writer locked onto the response stream?
from deno.
If you're using a TransformStream
as shown here, you definitely need to catch the write exceptions as those are how the close signal is propagated back through the chain.
We should definitely improve this error message to help point to the source of the error, however.
Note that locking and unlocking the stream is a bit unnecessary -- you should be able to just get the writer once and keep writing to it.
from deno.
IIRC I didn't realize that the write
was returning a promise, and at first I just wrapped it in a try / catch
without an await
. This seems to be a source of frustration for more than a few people, especially if you don't actually need the result of the call, then it's very easy to forget the await
.
@mmastrac is right, you don't need to lock and unlock continually, although if others need the writer than you may need to do this. This isn't best design, but the point was that it appeared to be uncatchable, but in the end it wasn't (which is why I closed this). I have seen other cases of uncatchable exceptions though (mostly around web sockets) but that was 2+ years ago and I think they have been resolved now.
from deno.
Related Issues (20)
- suggestion: Customized headers for upgradewebsocket()
- Docusaurus compatibility
- `ChildProcess` kill causes "Uncaught (in promise) BrokenPipe: Broken pipe (os error 32)" error HOT 2
- Language server type inference failure after 1.44.0
- deno test - default test file pattern no longer works (regression)
- feat: Add support for Cobertura XML coverage reporting HOT 4
- LSP workspace does not recognize package `imports` field in config
- jsxImportSource freezes lsp when not in workspace
- Cannot use jsr.json as workspace member outside deno publish HOT 7
- 'main' panicked HOT 1
- Support bare specifiers for npm package members in a workspace
- bug(net): http2 protocol error since deno 1.45
- Bug: Command `deno add` logs error for JSR package without default export
- Bug: LSP errors in VSCode opening built-in Typescript/Deno `d.ts` files
- Publishing JSR pkg that resolves to npm workspace member that's a JSR dep should error?
- deno compile: node addons gets error `missing symbol called`
- Compilation error during cargo install HOT 3
- `node:tty` -> N.WriteStream.prototype.hasColors is not a function
- File with just `+` does not report syntax error HOT 2
- Websocket behaviour change since 1.44.3 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deno.