Skip to content

Conversation

@IlyasShabi
Copy link
Contributor

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 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 IlyasShabi force-pushed the stream-event-names branch 2 times, most recently from 34542ca to bf229ca Compare January 1, 2024 12:52
@IlyasShabi 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
Copy link
Member

Qard commented Jan 1, 2024

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? 🙂

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.

LGTM, please add a test :]

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

Copy link
Member

@Qard Qard left a comment

Choose a reason for hiding this comment

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

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. 🤔

@lpinca
Copy link
Member

lpinca commented Jan 2, 2024

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
Copy link
Contributor Author

IlyasShabi commented Feb 18, 2024

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 lpinca added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 20, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 20, 2024
@nodejs-github-bot
Copy link
Collaborator

@IlyasShabi
Copy link
Contributor Author

I think flaky tests 🤔 no ?
@lpinca

@lpinca
Copy link
Member

lpinca commented Feb 20, 2024

Yes.

@nodejs-github-bot
Copy link
Collaborator

@IlyasShabi
Copy link
Contributor Author

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

@nodejs-github-bot
Copy link
Collaborator

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

@marco-ippolito marco-ippolito added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 27, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 27, 2024
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@Qard Qard added the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 27, 2024
@nodejs-github-bot 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
@nodejs-github-bot
Copy link
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 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 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 nodejs-github-bot merged commit a51efa2 into nodejs:main Feb 27, 2024
@nodejs-github-bot
Copy link
Collaborator

Landed in a51efa2

marco-ippolito pushed a commit that referenced this pull request Feb 29, 2024
PR-URL: #51331
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
marco-ippolito pushed a commit that referenced this pull request Feb 29, 2024
PR-URL: #51331
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@marco-ippolito 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 <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
richardlau pushed a commit that referenced this pull request Mar 25, 2024
PR-URL: #51331
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@richardlau richardlau mentioned this pull request Mar 25, 2024
rdw-msft pushed a commit to rdw-msft/node that referenced this pull request Mar 26, 2024
PR-URL: nodejs#51331
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@IlyasShabi IlyasShabi deleted the stream-event-names branch October 16, 2024 18:43
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