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
Open
robobun
wants to merge
3
commits into
main
Choose a base branch
from
robobun/efdc6321/serve-idle-warn-once
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+84
−35
Open
Changes from all commits
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,73 @@ | ||
| 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 has to wait for the default 10 second timeout on both connections. | ||
| // That is longer than the default per-test timeout, so this test sets one. | ||
| 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 seen = []; | ||
| const server = Bun.serve({ | ||
| port: 0, | ||
| hostname: "127.0.0.1", | ||
| development: true, | ||
| http2: true, | ||
| async fetch(req) { | ||
| seen.push(req.headers.get("x-proto")); | ||
| await req.text(); | ||
| return new Response("ok"); | ||
| }, | ||
| }); | ||
|
|
||
| // The server closes each connection when its idle timeout fires. The | ||
| // request count proves that both requests reached the handler before | ||
| // that, so a client that failed early cannot pass as a timeout. | ||
| let remaining = 2; | ||
| function done() { | ||
| if (--remaining === 0) { | ||
| console.log("both closed, requests seen: " + seen.sort().join(",")); | ||
| 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\\nX-Proto: h1\\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": "/", "x-proto": "h2" }); | ||
| stream.on("error", () => {}); | ||
| stream.write("abc"); | ||
| `, | ||
| ], | ||
| 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 closed, requests seen: h1,h2\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.
|
||
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.