Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@debadree25
Copy link
Member

Fixes: #37220
Refs: #36607

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Feb 4, 2023
@debadree25
Copy link
Member Author

debadree25 commented Feb 4, 2023

I think this would require further discussion since the conversation on the original issue stopped at 2021, nonetheless have tried to implement the discussed details until then and have added tests

cc @benjamingr, @jasnell

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would need documentation, as well as tests with invalid types/values to ensure we correctly validate the input.

@aduh95 aduh95 added the semver-minor PRs that contain new features and should be released in the next minor version. label Feb 4, 2023
@debadree25
Copy link
Member Author

Yes adding to those tests,

Docs can I update after this is confirmed that this change is acceptable?

const ac = new AbortController();
aborted(ac.signal, {}).then(common.mustNotCall());
setImmediate(() => {
global.gc();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does GC accomplish here? That the aborted() promise is collected before abort() is called?

I don't know if that kind of GC observability is a good thing. Maybe it works now but GC changes can break such patterns. Looks fragile.

Copy link
Member Author

@debadree25 debadree25 Feb 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically want to cleanup the empty object to check if the listener is removed when the resource is cleaned by the gc, unsure of any other ways to test this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's just for testing, then it's probably fine. I mean, it could still break in the future but we can revisit if and when that happens.

I'd advise against documenting that behavior though. It's simply not very robust.

Copy link
Member

@benjamingr benjamingr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM, missing docs (this should be marked as experimental, and as for where it should live I'll ping some TSC folk and ask)

@benjamingr
Copy link
Member

@ronag @mcollina @jasnell where would a method for (safely, memory leak wise) getting a promise for when a signal is aborted live?

events? util?

@debadree25
Copy link
Member Author

Have added to the docs, @benjamingr @aduh95

debadree25 and others added 3 commits February 5, 2023 11:07
Co-authored-by: Antoine du Hamel <[email protected]>
Co-authored-by: Antoine du Hamel <[email protected]>
*/
async function aborted(signal, resource) {
if (signal === undefined) {
throw new ERR_INVALID_ARG_TYPE('signal', 'AbortSignal', signal);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have added this check since turns out changing the condition in validateAbortSignal() immediately results in the build breaking, so i assume its probably not a bug but would like a review here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like a common pattern across to the codebase to check for undefined and then validate the signal so i think its probably fine?

@aduh95 aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 7, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 7, 2023
@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added experimental Issues and PRs related to experimental features. commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Feb 7, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 7, 2023
@nodejs-github-bot nodejs-github-bot merged commit 6d584ae into nodejs:main Feb 7, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in 6d584ae

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. experimental Issues and PRs related to experimental features. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a utility for knowing an AbortSignal was aborted

7 participants