-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
feat(core) support AbortSignal in Deno.listen #11569
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c9df4e1
feat(core) support AbortSignal in Deno.listen
benjamingr 3873c43
signal ref
benjamingr 82b9986
types
benjamingr b193404
async fn
benjamingr ba494b1
run deno format
benjamingr 23c0253
no reason for this test to be different from all the other ones
benjamingr 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 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 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That won't help - it still leaks the listener :) Happy to elaborate if that is unclear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's true that function captures everything
if v8 is failing to optimize that without any invocations, we can move event callback creation outside scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evanwashere even if the capture was only of the listener this is still a memory leak since the listener itself is captured.
Weak event listeners need to be baked into the event target implementation itself for this to not leak (here is an example how I did it in Node.js nodejs/node#36607 and I am happy to point to whatwg discussions).
That said - another (not bad) alternative is to expose a way to know when the listener is closed (and remove the handler then) but I didn't want to propose a change of the API of Deno.listen just for that :]
(This leak is small and not very problematic to be fair)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
listener is wrapped in weakref, so capture won't matter and problem will be fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the fact it needs a separate fix is why I added a TODO for it :) The actual leak here is contrived, edge-casey and not that bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bit of a drive-by comment but can't this be fixed with a WeakMap?
(Use of primordials omitted for brevity.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bnoordhuis that would still leak the
handleAbort
function reference.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not a problem though, is it? The solutions outlined earlier leak because they create new closures every time, whereas the
handleAbort()
closure is created only once (and at the top-level so it's going to stay around forever anyway.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bnoordhuis is the
handleAbort
reference still going to be in the listeners array?The "interesting" case here is a long-lived signal (imagine a signal owned by a controller that gets aborted on SIGINT for graceful shutdown) that gets registered often (imagine in this case you start a server on every request and do something).
Since this is
Deno.listen
it's not very likely - but that's the case we guarded against in Node