denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
96.75k stars 5.34k forks source link

http2 server closing stream exception #26234

Open TobyEalden opened 1 week ago

TobyEalden commented 1 week ago

Version: deno 2.0.0 (stable, release, aarch64-apple-darwin)

As part of investigation into https://github.com/denoland/deno/issues/24845, I wrote a test that exposed another (seemingly unrelated) issue.

If an http2 server closes the stream while a client is connected an exception is thrown:

error: Uncaught (in promise) Http: error reading a body from connection: stream closed because of a broken pipe
    at async Object.pull (ext:deno_web/06_streams.js:938:27)

To reproduce the issue see https://github.com/TobyEalden/deno-http2-stream-test

I can't see a way to easily catch or avoid this error other than using a setTImout as shown here, and in any case the same code running under nodejs works as expected.

leomongeg commented 3 days ago

Hi, I don't know if this is related but I'm facing a similar issue with this error output, maybe can help in the tracing of the error:

Execution Command: GRPC_VERBOSITY=debug GRPC_TRACE=all deno run -A dist/src/main.cjs

Deno Version: deno 2.0.1 (stable, release, aarch64-apple-darwin) v8 12.9.202.13-rusty typescript 5.6.2

Output:

D 2024-10-19T18:32:06.865Z | v1.12.2 90944 | server | (1) Server constructed
D 2024-10-19T18:32:06.868Z | v1.12.2 90944 | server | (1) bindAsync port=0.0.0.0:3000
D 2024-10-19T18:32:06.868Z | v1.12.2 90944 | dns_resolver | Resolver constructed for target dns:0.0.0.0:3000
D 2024-10-19T18:32:06.868Z | v1.12.2 90944 | dns_resolver | Returning IP address for target dns:0.0.0.0:3000
D 2024-10-19T18:32:06.870Z | v1.12.2 90944 | server | (1) Attempting to bind 0.0.0.0:3000
D 2024-10-19T18:32:06.871Z | v1.12.2 90944 | server | (1) Successfully bound 0.0.0.0:3000
[Nest] 90944  - 10/19/2024, 12:32:06 PM     LOG [NestMicroservice] Nest microservice successfully started +84ms
>>> Error in Http2Server Error [ERR_HTTP2_SOCKET_UNBOUND]: The socket has been disconnected from the Http2Session
    at Object.get (node:http2:92:19)
    at Http2Server.<anonymous> (file:///Users/leonardo/Development/projects/deno-poc-nestjs/node_modules/.deno/@grpc+grpc-js@1.12.2/node_modules/@grpc/grpc-js/build/src/server.js:1154:148)
    at Http2Server.emit (ext:deno_node/_events.mjs:393:28)
    at Http2Server.<anonymous> (node:http2:1214:14)
    at Http2Server.emit (ext:deno_node/_events.mjs:393:28)
    at TCP._onconnection (node:net:1127:8)
    at TCP.#accept (ext:deno_node/internal_binding/tcp_wrap.ts:356:12)
    at eventLoopTick (ext:core/01_core.js:175:7) {
  code: "ERR_HTTP2_SOCKET_UNBOUND",
  name: "Error"
}

Regards