Repository navigation
fix(microservices): settle the tcp listen callback on any listen error - #17922
Merged
kamilmysliwiec merged 1 commit intoSep 30, 2026
Merged
kamilmysliwiec merged 1 commit into
kamilmysliwiec merged 1 commit into
Conversation
ServerTCP.listen only passed EADDRINUSE and ECONNREFUSED to the callback. Node runs the listen callback on success only, so every other listen error (EACCES on a privileged port, EADDRNOTAVAIL for a host address the machine does not own) was logged and then nothing settled: the promise behind app.listen() stayed pending forever and the status never left its previous value. The callback now runs exactly once, with the first listen error whatever its code, or when the server starts listening, the way the mqtt and rmq servers settle theirs. An error emitted after listening stays with the permanent error listener: it does not reach the callback again and does not flip the status to disconnected. Closes nestjs#17921
johnnyhuirilef
force-pushed
the
fix/tcp-listen-settles-on-any-error
branch
from
September 29, 2026 14:22
15f7b37 to
fe4dfd3
Compare
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
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.
PR Checklist
PR Type
What is the current behavior?
Issue Number: closes #17921
ServerTCP.listen()only passes a listen error to its callback when the code isEADDRINUSEorECONNREFUSED. Node calls the listen callback on success only, so any other listen failure is logged and nothing settles.await app.listen()stays pending, and the status keeps its previous value.Measured with the repro on 12.1.1:
What is the new behavior?
The listen callback runs exactly once. It runs with the first listen error, whatever its code, or when the server starts listening. It uses the same
listenCallbackidiom thatServerMqttandServerRMQuse to settle theirs (#17641, #17675).An error emitted after the server is listening stays with the permanent error listener. It is logged as before, and it neither reaches the callback again nor flips the status to disconnected.
The same repro against a local build of this branch:
This is the microservice counterpart of #3209 / #3360, which made the HTTP
listen()reject on bind failures.Does this PR introduce a breaking change?
app.listen()used to hang forever for these errors. It now rejects, as it already did forEADDRINUSE. Nothing exported changes.EADDRINUSEis still exported fromconstants.ts; only its import inserver-tcp.tsbecame unused.Other information
Three of the new tests fail without the source change:
EACCES,EADDRNOTAVAIL, and an error without a code. The others pin the behavior that must not change:EADDRINUSEandECONNREFUSEDstill reach the callback, and an error after the server is listening neither calls it again nor reports the status as disconnected.