Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BadResource Error with Request.text() in Deno #27132

Open
PutziSan opened this issue Nov 28, 2024 · 0 comments
Open

BadResource Error with Request.text() in Deno #27132

PutziSan opened this issue Nov 28, 2024 · 0 comments

Comments

@PutziSan
Copy link

PutziSan commented Nov 28, 2024

Version: deno 2.1.1 (stable, release, x86_64-unknown-linux-gnu)

The following Deno server code produces seemingly random BadResource: Bad resource ID errors:

Deno.serve(async (req) => new Response(await req.text()));

Observed Behavior

The error probably occurs when the TCP connection is closed before the request body is fully read. Example error:

BadResource: Bad resource ID
    at readableStreamCollectIntoUint8Array (ext:deno_web/06_streams.js:1060:23)
    at InnerBody.consume (ext:deno_fetch/22_body.js:163:14)
    at consumeBody (ext:deno_fetch/22_body.js:255:34)
    at Request.text (ext:deno_fetch/22_body.js:351:16)
    at file:///<...>/server.ts:1:50
    at ext:deno_http/00_serve.ts:382:26
    at ext:deno_http/00_serve.ts:573:33
    at eventLoopTick (ext:core/01_core.js:175:7) {
  name: "BadResource"
}

A Wireshark capture of a failed request shows the client closing the connection immediately after sending a POST request.

495880	2024-11-26 09:35:57,705529846	127.0.0.1	127.0.0.1	HTTP/JSON	207	POST / HTTP/1.1 , JavaScript Object Notation (application/json)
496787	2024-11-26 09:35:57,714119877	127.0.0.1	127.0.0.1	TCP	66	56952 → 8080 [FIN, ACK] Seq=14383 Ack=10808 Win=65536 Len=0 TSval=658758687 TSecr=658758679
497150	2024-11-26 09:35:57,716091194	127.0.0.1	127.0.0.1	TCP	66	8080 → 56952 [FIN, ACK] Seq=10808 Ack=14384 Win=65536 Len=0 TSval=658758689 TSecr=658758679
497151	2024-11-26 09:35:57,716093907	127.0.0.1	127.0.0.1	TCP	66	56952 → 8080 [ACK] Seq=14384 Ack=10809 Win=65536 Len=0 TSval=658758689 TSecr=658758689

Expected Behavior

The server should not throw an error or throw a more descriptive error.

Context

I encountered this error while load testing my Deno server using wrk. The error occurred only on the end of a load test run, but not on every run.

Steps to Reproduce

A repository with unstable reproduction steps is available: deno-server-bug-repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant