Repository navigation
[fix] Call the _final() callback if the socket is closed prematurely - #2345
Open
mkantautas wants to merge 1 commit into
Open
mkantautas wants to merge 1 commit into
mkantautas wants to merge 1 commit into
Conversation
If the socket was destroyed before it was finished, for example because the closing handshake timed out or the connection was reset, the callback of `duplex._final()` was never called. The `'finish'` and `'close'` events were not emitted and the stream was never destroyed.
Member
|
As with #2338 once the |
This branch has not been deployed
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.
If the writable side of a stream returned by
createWebSocketStream()is ended and the socket is destroyed before it emits'finish', the_final()callback is never called. This happens when the other peer does not answer the close frame and the close timer destroys the socket, or when the connection is reset. The stream never emits'finish'or'close'and is never destroyed, sopipeline()never calls its callback.This makes
_final()also listen for the'close'event of the socket. The listener is prepended so that'finish'is still emitted before'end'and the existing'end'listener destroys the stream. Without that, the(2/2)test fails on Node.js >= 16. If the stream is being destroyed, the callback is not called, sopipeline()still reports the error passed toduplex.destroy().#2338 is related. It handles the case where the socket is already destroyed when
_final()is called, and does not fix this one, where the socket is destroyed while_final()waits for'finish'.