GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix regression in signal unlisten and document current EE behaviour by sam-github · Pull Request #687 · nodejs/node

Conversation

@sam-github

@sam-github sam-github commented Feb 2, 2015

Copy link
Copy Markdown
Contributor

process.removeAllListeners() doesn't work for signals. It should, and it used to, prior to 56668f5

I originally PRed a fix for this in nodejs/node-v0.x-archive#8953. That fix is a one-liner, wherein a subtle optimization in EventEmitter.removeAllListeners() is evaded by a seeming no-op process.on('removeListener', function(){}), which is pretty awful from a comprehensibility point of view.

src/node.js is simpler and more understandable if it just uses the new/remove listener events, but they are theoretically useless for this kind of use-case, since the documentation is officially weasely about whether they fire before or after the listener is actually added. see: nodejs/node-v0.x-archive#8853 and piscisaureus@ff350f7

I've never seen the new/remove listener used for any purpose other than what node itself could use it for: detecting whether there is indeed a listener for an event, and starting or stopping some processing accordingly. It should be easier to use the EE for this.

Even if you don't agree the indeterminancy in the EE API should be removed, node is free to depend on implementation details of itself, so 90a5e2b doesn't require c1d5fab. For node to assume that the EE behaves as it does seems better than my original fix/hack in sam-github@06b6e75

R=@bnoordhuis

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
sam-github added 2 commits February 2, 2015 10:00
@sam-github
events: remove indeterminancy from event ordering
e53bd67
The order of the `newListener` and `removeListener` events with respect
to the actual adding and removing from the underlying listeners array
should be deterministic. There is no compelling reason for leaving it
indeterminate. Changing the ordering is likely to result in breaking
code that was unwittingly relying on the current behaviour, and the
indeterminancy makes it impossible to use these events to determine when
the first or last listener is added for an event.
@sam-github
process: fix regression in unlistening signals
09653fb
When the last signal listener is removed, the signal wrap should be
closed, restoring the default signal handling behaviour. This is done in
a (patched) process.removeListener(). However, events.removeAllListeners
has an optimization to avoid calling removeListener() if there are no
listeners for the 'removeListener' event, introduced in 56668f5. That
caused the following code to fail to terminate:

    process.stdin.resume();
    function listener() {};
    process.on('SIGINT', listener);
    process.removeAllListeners('SIGINT');
    process.kill(process.pid, 'SIGINT')

while the following will terminate:

    process.stdin.resume();
    function listener() {};
    process.on('SIGINT', listener);
    process.removeListener('SIGINT', listener);
    process.kill(process.pid, 'SIGINT')

Replace the method patching with use of the 'newListener' and
'removeListener' events, which will fire no matter which methods are
used to add or remove listeners.
@sam-github
sam-github force-pushed the fix-regression-in-signal-unlisten branch from 90a5e2b to 09653fb Compare February 2, 2015 18:01
@sam-github

sam-github commented Feb 2, 2015

Copy link
Copy Markdown
Contributor Author

@bnoordhuis fixed the things you commented on, thanks, and rebased, PTAL

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bnoordhuis pushed a commit that referenced this pull request Feb 2, 2015
@sam-github @bnoordhuis
events: remove indeterminancy from event ordering
233e333
The order of the `newListener` and `removeListener` events with respect
to the actual adding and removing from the underlying listeners array
should be deterministic. There is no compelling reason for leaving it
indeterminate. Changing the ordering is likely to result in breaking
code that was unwittingly relying on the current behaviour, and the
indeterminancy makes it impossible to use these events to determine when
the first or last listener is added for an event.

PR-URL: #687
Reviewed-By: Ben Noordhuis <[email protected]>
bnoordhuis pushed a commit that referenced this pull request Feb 2, 2015
@sam-github @bnoordhuis
process: fix regression in unlistening signals
e9eb2ec
When the last signal listener is removed, the signal wrap should be
closed, restoring the default signal handling behaviour. This is done in
a (patched) process.removeListener(). However, events.removeAllListeners
has an optimization to avoid calling removeListener() if there are no
listeners for the 'removeListener' event, introduced in 56668f5. That
caused the following code to fail to terminate:

    process.stdin.resume();
    function listener() {};
    process.on('SIGINT', listener);
    process.removeAllListeners('SIGINT');
    process.kill(process.pid, 'SIGINT')

while the following will terminate:

    process.stdin.resume();
    function listener() {};
    process.on('SIGINT', listener);
    process.removeListener('SIGINT', listener);
    process.kill(process.pid, 'SIGINT')

Replace the method patching with use of the 'newListener' and
'removeListener' events, which will fire no matter which methods are
used to add or remove listeners.

PR-URL: #687
Reviewed-By: Ben Noordhuis <[email protected]>
@bnoordhuis

bnoordhuis commented Feb 2, 2015

Copy link
Copy Markdown
Member

Thanks Sam, landed in 233e333...e9eb2ec.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis bnoordhuis closed this Feb 2, 2015
@bnoordhuis bnoordhuis mentioned this pull request Feb 2, 2015
events: optimize various functions #601
Closed
@sam-github
sam-github deleted the fix-regression-in-signal-unlisten branch February 17, 2015 02:55
This was referenced Jun 23, 2023
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#567
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#573
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#577
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#578
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#581
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#583
Open
[Snyk] Security upgrade xo from 0.25.4 to 0.53.0 aliscco/alisco-node#586
Open
[Snyk] Security upgrade xo from 0.24.0 to 0.53.0 aliscco/alisco-node#587
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#589
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#594
Open
[Snyk] Security upgrade xo from 0.25.4 to 0.53.0 aliscco/alisco-node#596
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#597
Open
[Snyk] Security upgrade xo from 0.25.4 to 0.53.0 aliscco/alisco-node#599
Open
[Snyk] Security upgrade xo from 0.25.4 to 0.53.0 aliscco/alisco-node#601
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#602
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#605
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#610
Open
[Snyk] Security upgrade xo from 0.37.1 to 0.53.0 aliscco/alisco-node#612
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#613
Open
[Snyk] Fix for 1 vulnerabilities aliscco/alisco-node#617
Open
This was referenced Jul 7, 2023
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#60
Open
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#62
Open
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#66
Open
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#71
Open
[Snyk] Fix for 7 vulnerabilities leonardoadame/node#74
Open
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#78
Open
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#80
Open
[Snyk] Fix for 7 vulnerabilities leonardoadame/node#83
Open
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#84
Open
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#87
Open
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#92
Open
[Snyk] Fix for 4 vulnerabilities leonardoadame/node#93
Open
[Snyk] Fix for 3 vulnerabilities leonardoadame/node#94
Open
[Snyk] Fix for 7 vulnerabilities leonardoadame/node#102
Open
[Snyk] Fix for 8 vulnerabilities leonardoadame/node#107
Open
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#111
Open
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#113
Open
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#120
Open
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#122
Open
[Snyk] Fix for 2 vulnerabilities leonardoadame/node#125
Open
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#134
Open
[Snyk] Fix for 5 vulnerabilities leonardoadame/node#137
Open
[Snyk] Fix for 7 vulnerabilities leonardoadame/node#138
Open
@jefeaguila jefeaguila mentioned this pull request Feb 11, 2024
[Snyk] Fix for 1 vulnerabilities jefeaguila/node#37
Open
@buzzlightyear726 buzzlightyear726 mentioned this pull request Feb 11, 2024
[Snyk] Fix for 1 vulnerabilities buzzlightyear726/node#39
Open
@jefeaguila jefeaguila mentioned this pull request Feb 11, 2024
[Snyk] Fix for 1 vulnerabilities jefeaguila/node#41
Open
@buzzlightyear726 buzzlightyear726 mentioned this pull request Feb 11, 2024
[Snyk] Fix for 1 vulnerabilities buzzlightyear726/node#44
Open
@Renukaloch Renukaloch mentioned this pull request Feb 11, 2024
[Snyk] Fix for 1 vulnerabilities Renukaloch/node#26
Open
@buzzlightyear726 buzzlightyear726 mentioned this pull request Feb 12, 2024
[Snyk] Fix for 1 vulnerabilities buzzlightyear726/node#51
Open
@ikreymer ikreymer mentioned this pull request Sep 17, 2024
direct fetch: when cancelling due to redirect, read full body webrecorder/browsertrix-crawler#688
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@sam-github @bnoordhuis
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.