-
Notifications
You must be signed in to change notification settings - Fork 370
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
Conversation
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. |
There was a problem hiding this 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.
src/utils/api-request.ts
Outdated
socket.setTimeout(timeout, timeoutCallback); | ||
socket.on('end', () => { | ||
socket.setTimeout(0); | ||
socket.setMaxListeners(socket.getMaxListeners() - 1); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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 inHttpClient.send
namely inAsyncHttpCall.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 theafterEach
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
afterEach
totest/integration/auth.spec.ts
which expects theprocess.on
not be called with anMaxListenersExceededWarning
error.API Changes