Repository navigation
event_loop: make DeferredTaskQueue::run tolerate re-entrant map mutation #32703
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
Merged
Jarred-Sumner
merged 10 commits into
main
from
farm/c4842cba/deferred-task-queue-reentrant
Jul 30, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1a2eed8
event_loop: make DeferredTaskQueue::run tolerate re-entrant map mutation
robobun 800ac36
Clarify remaining-count comment in DeferredTaskQueue::run
robobun 3e90170
ci: retrigger
robobun 6acebc2
Move DeferredTaskQueue regression test to its own file and budget for…
robobun e5cf4e9
Correct the ASAN_MULTIPLIER comment
robobun 2e741b3
Move the DeferredTaskQueue test back into node-http2-streams-rehash.t…
robobun ab84bbd
Shorten the ASAN_MULTIPLIER comment to three lines
robobun 1b56f3d
Merge remote-tracking branch 'origin/main' into farm/c4842cba/deferre…
robobun 17d2a84
Move the run() re-entrancy rationale into the module doc
robobun 0a4c96b
Merge remote-tracking branch 'origin/main' into farm/c4842cba/deferre…
robobun 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
88 changes: 88 additions & 0 deletions
88
test/js/node/http2/node-http2-deferred-task-queue.fixture.js
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,88 @@ | ||
| // DeferredTaskQueue::run iterates the auto-flusher map and invokes each | ||
| // entry's callback. H2FrameParser::on_auto_flush calls flush -> uncork -> | ||
| // unregister_auto_flush, which removes its own entry from the map while | ||
| // run() is iterating, and then returns true (keep). The loop must not | ||
| // assume the map length is unchanged after the callback returns. | ||
| // | ||
| // This fixture registers two auto-flushers in the same microtask so they | ||
| // share one DeferredTaskQueue::run pass: an H2FrameParser (via | ||
| // client.request, which corks) and an HTTPServerWritable (via a small | ||
| // controller.write on a Bun.serve direct stream, which buffers and | ||
| // registers). The H2 entry is first in the insertion-ordered map; when its | ||
| // callback removes it and returns true, run() must re-read the map length | ||
| // before indexing the next slot. | ||
|
|
||
| const http2 = require("node:http2"); | ||
| const { once } = require("node:events"); | ||
|
|
||
| async function main() { | ||
| const h2srv = http2.createServer(); | ||
| h2srv.on("stream", s => { | ||
| s.respond({ ":status": 200 }); | ||
| s.end("ok"); | ||
| }); | ||
| h2srv.on("error", () => {}); | ||
| h2srv.listen(0, "127.0.0.1"); | ||
| await once(h2srv, "listening"); | ||
| const h2port = h2srv.address().port; | ||
|
|
||
| const client = http2.connect(`http://127.0.0.1:${h2port}`); | ||
| client.on("error", () => {}); | ||
| await once(client, "connect"); | ||
|
|
||
| let resolveController; | ||
| const controllerPromise = new Promise(r => (resolveController = r)); | ||
| let resolveDone; | ||
| const donePromise = new Promise(r => (resolveDone = r)); | ||
|
|
||
| const app = Bun.serve({ | ||
| port: 0, | ||
| fetch() { | ||
| return new Response( | ||
| new ReadableStream({ | ||
| type: "direct", | ||
| pull(controller) { | ||
| resolveController(controller); | ||
| return donePromise; | ||
| }, | ||
| }), | ||
| ); | ||
| }, | ||
| }); | ||
|
|
||
| const fetchPromise = fetch(`http://127.0.0.1:${app.port}/`).then(r => r.text()); | ||
| const controller = await controllerPromise; | ||
|
|
||
| // Move to a fresh event-loop task so the registrations below land in a | ||
| // microtask whose drain runs DeferredTaskQueue::run directly after. | ||
| await new Promise(r => setImmediate(r)); | ||
|
|
||
| queueMicrotask(() => { | ||
| // H2FrameParser::write -> cork -> register_auto_flush (map[0]). | ||
| const req = client.request({ ":path": "/" }); | ||
| req.on("error", () => {}); | ||
| req.resume(); | ||
| // HTTPServerWritable::write (< highWaterMark) -> register_auto_flusher (map[1]). | ||
| controller.write("x"); | ||
| }); | ||
| await new Promise(r => setImmediate(r)); | ||
|
|
||
| controller.write("y"); | ||
| controller.close(); | ||
| resolveDone(); | ||
| const body = await fetchPromise; | ||
| if (body !== "xy") throw new Error(`unexpected body: ${JSON.stringify(body)}`); | ||
|
|
||
| app.stop(true); | ||
| client.close(); | ||
| await new Promise(r => h2srv.close(r)); | ||
| console.log("OK"); | ||
| } | ||
|
|
||
| main().then( | ||
| () => process.exit(0), | ||
| e => { | ||
| console.error(e); | ||
| process.exit(1); | ||
| }, | ||
| ); |
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
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.