Repository navigation
node:dgram: run 'message' in the async context of createSocket() #47609
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
13
commits into
main
Choose a base branch
from
robobun/ddeb441b/dgram-handle-async-context
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.
+1,128
−4
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
00a4d53
node:dgram: run 'message' in the async context of createSocket()
robobun 7807ccb
node:dgram tests: wire failures, and drop the rows that pin an unboun…
robobun a418393
Merge remote-tracking branch 'origin/main' into robobun/ddeb441b/dgra…
robobun 3e4777e
node:dgram tests: reject when connect() fails
robobun db1346b
node:dgram tests: a socket error after 'listening' rejects the wait f…
robobun b8905b1
node:dgram: a queued send() with no callback keeps no async context
robobun b435377
node:dgram: swap the async context in place, not through AsyncContext…
robobun 2ce33fe
node:dgram tests: import the internals at module scope, and close the…
robobun fe0b0e9
node:dgram: keep the async context of a queued send() in a table, not…
robobun a0224f3
Merge remote-tracking branch 'origin/main' into robobun/ddeb441b/dgra…
robobun a703962
node:dgram: a handle does not keep an async context that has a frame …
robobun eb6fb71
node:dgram: one comment line for the handle's frame, and the reason f…
robobun c9101b4
node:dgram: walk the frames of createSocket() in one pass, and let th…
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
53 changes: 53 additions & 0 deletions
53
test/aot/a-saved-async-context-keeps-no-method-of-a-store-that-nothing-calls.test.ts
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,53 @@ | ||
| // node:dgram saves the async context of createSocket() and of a queued send(). Where the compiler cannot follow a saved context, it | ||
| // takes every AsyncLocalStorage store of the program to be used by code it cannot see, and keeps all that a store names. So a method | ||
| // of a store that nothing calls shows it: the report says whether what only that method names was removed. node:child_process | ||
| // reaches bind() for a socket that a child receives. | ||
| import { expect } from "bun:test"; | ||
| import { bunEnv, bunExe, tempDir } from "harness"; | ||
| import { test } from "./supported"; | ||
|
|
||
| const collation = "Intl.Collator and localeCompare ("; | ||
|
|
||
| test.concurrent.each([ | ||
| [ | ||
| "binds a node:dgram socket and sends on it", | ||
| `import { createSocket } from "node:dgram"; | ||
| const socket = createSocket("udp4"); | ||
| socket.bind(0, "127.0.0.1", () => socket.send("x", socket.address().port, "127.0.0.1", () => socket.close()));`, | ||
| ], | ||
| [ | ||
| "spawns a child process", | ||
| `import { spawn } from "node:child_process"; | ||
| spawn(process.execPath, ["--version"]).on("exit", () => {});`, | ||
| ], | ||
| ])( | ||
| "a program that %s keeps nothing for a method of a store that it never calls", | ||
| async (_, uses) => { | ||
| using dir = tempDir("aot-saved-context", { | ||
| "main.ts": `// @ts-nocheck | ||
| import { AsyncLocalStorage } from "node:async_hooks"; | ||
| class Store { | ||
| used() { return 1; } | ||
| neverCalled() { return new Intl.Collator("en").compare("a", "b"); } | ||
| } | ||
| const storage = new AsyncLocalStorage(); | ||
| const store = new Store(); | ||
| console.log(storage.run(store, () => store.used())); | ||
| ${uses} | ||
| `, | ||
| }); | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "check", "--aot", "--no-pretty", "--explain=trim", "main.ts"], | ||
| cwd: String(dir), | ||
| env: { ...bunEnv, NO_COLOR: "1" }, | ||
| stdout: "ignore", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stderr, exitCode] = await Promise.all([proc.stderr.text(), proc.exited]); | ||
| expect({ collation: stderr.split("\n").filter(line => line.includes(collation)), exitCode }).toEqual({ | ||
| collation: [expect.stringContaining(`aot: trim: removed ${collation}`)], | ||
| exitCode: 0, | ||
| }); | ||
| }, | ||
| 600_000, | ||
| ); |
Oops, something went wrong.
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.