Skip to content
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

fix: Unregister socket timeout listener to prevent MaxListenersExceededWarning #1993

Merged
merged 5 commits into from Dec 13, 2022

Conversation

dwirz
Copy link
Contributor

@dwirz dwirz commented Nov 29, 2022

Hey there,

after updating our application to node 19 we noticed that the firebase package is causing a MaxListenersExceededWarning error. The error occurs in the underlying method call in HttpClient.send namely in AsyncHttpCall.execute. There the timeout listener is not removed after the socket is closed. I could provoke the error only in the integration tests, in the unit tests to the mentioned method the error does not occur. Therefore I added a listener spy check in the afterEach of the auth integration tests which should not be called.

Attention, the error only occurs with Node 19, if someone wants to test the behavior it must be done with this version.

Thanks for the great work – I am looking forward to your review.

PS: we mainly use the auth feature of firebase. so i may have missed something in other features/tests.

Discussion

Testing

  • Added afterEach to test/integration/auth.spec.ts which expects the process.on not be called with an MaxListenersExceededWarning error.

API Changes

  • No changes to API

@google-cla
Copy link

google-cla bot commented Nov 29, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Member

@lahirumaramba lahirumaramba left a comment

Choose a reason for hiding this comment

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

Hey @dwirz Thank you so much for your contribution! This makes senses to me. I left one comment.

socket.setTimeout(timeout, timeoutCallback);
socket.on('end', () => {
socket.setTimeout(0);
socket.setMaxListeners(socket.getMaxListeners() - 1);
Copy link
Member

Choose a reason for hiding this comment

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

Can this be a negative value? If so, should we add Math.max(emitter.getMaxListeners() - 1, 0) to make sure we don't set this to a negative value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense 👍 added Math.max

@dwirz dwirz removed their assignment Dec 10, 2022
@lahirumaramba lahirumaramba merged commit 1a34bc4 into firebase:master Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants