Repository navigation
Bun.serve: print the dev-mode idle timeout warning once for all protocols #43017
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { expect, test } from "bun:test"; | ||
| import { bunEnv, bunExe } from "harness"; | ||
|
|
||
| // https://github.com/oven-sh/bun/issues/43016 | ||
| // The dev-mode idle timeout warning is meant to print once per process. The | ||
| // HTTP/1 path and the HTTP/2 and HTTP/3 path each had their own once flag and | ||
| // their own text, so a process that timed out one request on each protocol | ||
| // printed the warning twice. | ||
| // | ||
| // The warning is only registered when `idleTimeout` is not passed, so the | ||
| // test waits for the default 10 second timeout on both connections. | ||
| test("Bun.serve prints the idle timeout warning once for HTTP/1 and HTTP/2 timeouts", async () => { | ||
| await using proc = Bun.spawn({ | ||
| cmd: [ | ||
| bunExe(), | ||
| "-e", | ||
| ` | ||
| import http2 from "node:http2"; | ||
| import net from "node:net"; | ||
|
|
||
| const server = Bun.serve({ | ||
| port: 0, | ||
| hostname: "127.0.0.1", | ||
| development: true, | ||
| http2: true, | ||
| async fetch(req) { | ||
| await req.text(); | ||
| return new Response("ok"); | ||
| }, | ||
| }); | ||
|
|
||
| let remaining = 2; | ||
| function done() { | ||
| if (--remaining === 0) { | ||
| console.log("both timed out"); | ||
| process.exit(0); | ||
| } | ||
| } | ||
|
|
||
| // HTTP/1: a POST whose body never completes. | ||
| const h1 = net.connect(server.port, "127.0.0.1", () => { | ||
| h1.write("POST / HTTP/1.1\\r\\nHost: x\\r\\nContent-Length: 100\\r\\n\\r\\nabc"); | ||
| }); | ||
| h1.on("error", () => {}); | ||
| h1.on("close", done); | ||
|
|
||
| // HTTP/2 (cleartext, prior knowledge): a POST stream that never ends. | ||
| const session = http2.connect("http://127.0.0.1:" + server.port); | ||
| session.on("error", () => {}); | ||
| session.on("close", done); | ||
| const stream = session.request({ ":method": "POST", ":path": "/" }); | ||
| stream.on("error", () => {}); | ||
| stream.write("abc"); | ||
|
robobun marked this conversation as resolved.
Resolved
|
||
| `, | ||
| ], | ||
| env: bunEnv, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
|
|
||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stdout).toBe("both timed out\n"); | ||
| const warning = "warn: Bun.serve() timed out a request after 10 seconds. Pass `idleTimeout` to configure."; | ||
| expect(stderr.split(warning).length - 1).toBe(1); | ||
| expect(stderr).not.toContain("[Bun.serve]: request timed out"); | ||
| expect(exitCode).toBe(0); | ||
| }, 30_000); | ||
|
robobun marked this conversation as resolved.
Resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.