FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

stream: fix eventNames() to not return not defined events by IlyasShabi · Pull Request #51331 · nodejs/node · GitHub

/ node Public

stream: fix eventNames() to not return not defined events - #51331

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
IlyasShabi:stream-event-names
Feb 27, 2024
Merged

stream: fix eventNames() to not return not defined events#51331
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
IlyasShabi:stream-event-names

Conversation

Copy link
Copy Markdown
Member

Fix issue #51302
As explained by @Qard, the root cause is that by default, we pre-allocate events here here

  1. Since those events are initially set to undefined, we should check the value of the listener before returning eventNames().
  2. I also believe that we are protected because we are not allowed to set a null or undefined listener.

I did different tests like:

const readableStream = createReadable();
readableStream.on('a', () => {});
readableStream.on('error', () => {});
console.log(readableStream.eventNames()); // ['a', 'error']
const readableStream = createReadable();
readableStream.on('a', () => {});
console.log(readableStream.eventNames()); // ['a']

I will add tests as soon as I can

nodejs-github-bot added events Issues and PRs related to the events subsystem / EventEmitter. needs-ci PRs that need a full CI run. labels Jan 1, 2024
IlyasShabi force-pushed the stream-event-names branch 2 times, most recently from 34542ca to bf229ca Compare January 1, 2024 12:52
IlyasShabi changed the title Fix stream eventNames to not return not defined events stream: fix eventNames() to not return not defined events Jan 1, 2024

Qard commented Jan 1, 2024
edited
Loading

Copy link
Copy Markdown
Member

Yep, that's basically what I had in mind. I'd maybe make it check if it's an array and non-empty though to be more accurate rather than just the simple check that it's not undefined. Can you add some tests? 🙂

benjamingr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM, please add a test :]

IlyasShabi force-pushed the stream-event-names branch 2 times, most recently from 9a4ba8d to 0c7adfc Compare January 1, 2024 21:34
benjamingr added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 1, 2024
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 1, 2024

Copy link
Copy Markdown
Collaborator

Qard left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM, but a suggestion: the tests currently rely on the implementation detail of streams doing the _events pre-allocation. It may be a good idea to manually reproduce the behaviour on a plain event listener as streams could change in the future to not do that anymore. 🤔

Comment thread lib/events.js Outdated

lpinca commented Jan 2, 2024

Copy link
Copy Markdown
Member

I wonder if it is better to override eventNames() only on classes where _events is pre-allocated. We don't do this with the base EventEmitter.

IlyasShabi commented Feb 18, 2024
edited
Loading

Copy link
Copy Markdown
Member Author

I wonder if it is better to override eventNames() only on classes where _events is pre-allocated. We don't do this with the base EventEmitter.

@lpinca I agree with you, this is related to Stream not EventEmitter, I pushed the changes, could you please check again ?
cc @Qard @benjamingr

lpinca added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 20, 2024
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 20, 2024

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Member Author

I think flaky tests 🤔 no ?
@lpinca

lpinca commented Feb 20, 2024

Copy link
Copy Markdown
Member

Yes.

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Member Author

Failed on this one wasi/test-wasi # TODO : Fix flaky test
@lpinca should I do something to merge this one ?

Copy link
Copy Markdown
Collaborator

lpinca added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 25, 2024
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 25, 2024

Copy link
Copy Markdown
Collaborator

marco-ippolito added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 27, 2024
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 27, 2024

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

Qard added the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 27, 2024
nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Feb 27, 2024

Copy link
Copy Markdown
Collaborator
Commit Queue failed
- Loading data for nodejs/node/pull/51331
✔  Done loading data for nodejs/node/pull/51331
----------------------------------- PR info ------------------------------------
Title      stream: fix eventNames() to not return not defined events (#51331)
   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
Branch     IlyasShabi:stream-event-names -> nodejs:main
Labels     events, needs-ci
Commits    1
 - stream: fix eventNames() to not return not defined events
Committers 1
 - Ilyas Shabi 
PR-URL: https://github.com/nodejs/node/pull/51331
Reviewed-By: Benjamin Gruenbaum 
Reviewed-By: Stephen Belanger 
Reviewed-By: Luigi Pinca 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/51331
Reviewed-By: Benjamin Gruenbaum 
Reviewed-By: Stephen Belanger 
Reviewed-By: Luigi Pinca 
--------------------------------------------------------------------------------
   ⚠  Commits were pushed since the last approving review:
   ⚠  - stream: fix eventNames() to not return not defined events
   ℹ  This PR was created on Mon, 01 Jan 2024 12:43:44 GMT
   ✔  Approvals: 3
   ✔  - Benjamin Gruenbaum (@benjamingr) (TSC): https://github.com/nodejs/node/pull/51331#pullrequestreview-1799869531
   ✔  - Stephen Belanger (@Qard): https://github.com/nodejs/node/pull/51331#pullrequestreview-1890807762
   ✔  - Luigi Pinca (@lpinca): https://github.com/nodejs/node/pull/51331#pullrequestreview-1890926622
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2024-02-27T21:35:07Z: https://ci.nodejs.org/job/node-test-pull-request/57477/
- Querying data for job/node-test-pull-request/57477/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/8072630772

Qard added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Feb 27, 2024
nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 27, 2024
nodejs-github-bot merged commit a51efa2 into nodejs:main Feb 27, 2024

Copy link
Copy Markdown
Collaborator

Landed in a51efa2

marco-ippolito pushed a commit that referenced this pull request Feb 29, 2024
PR-URL: #51331
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
marco-ippolito mentioned this pull request Mar 1, 2024
richardlau pushed a commit that referenced this pull request Mar 25, 2024
PR-URL: #51331
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
richardlau mentioned this pull request Mar 25, 2024
IlyasShabi deleted the stream-event-names branch October 16, 2024 18:43
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

events Issues and PRs related to the events subsystem / EventEmitter. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL