fix: Accept() must not close the listener socket on success#81
Open
cdgraff wants to merge 1 commit into
Open
Conversation
NodeSRT::Accept() called srt_close() on the listener socket on the success path, so the listener was destroyed after every accepted connection. In libsrt, srt_accept() returns the newly accepted socket and leaves the listener open so it can keep accepting - this diverged from that contract. A server could accept only one connection per listener; after the first accept() the listener went BROKEN then NONEXIST, and any further caller timed out. Working around it by re-creating the listener after every accept dropped its backlog of pending handshakes, so a burst of simultaneous callers lost all but one. Removes the success-path srt_close()/reset so Accept() only returns the accepted fd and leaves the listener open, matching libsrt semantics; the caller is responsible for closing the listener when done. The failure path is unchanged. Adds a regression test covering both the sync (SRT) and async (AsyncSRT) accept paths: it accepts several connections in a row from the same listener and asserts the listener stays LISTENING throughout. Fixes Eyevinn#79
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.
Summary
NodeSRT::Accept()(src/node-srt.cc) calledsrt_close()on the listener socket on the success path, so the listener was destroyed after every accepted connection.In libsrt,
srt_accept()returns the newly accepted socket and leaves the listener open so it can keep accepting - this diverged from that contract:accept()the listener wentBROKENthenNONEXIST, and any further caller timed out.Fix
Removes the success-path
srt_close(socketValue)(and the following no-op reassignment), soAccept()only returns the accepted fd and leaves the listener open, matching libsrt semantics. The caller is responsible for closing the listener when done. The failure path is unchanged.Test
Adds
spec/accept_keeps_listener_open_spec.js, a regression test covering both the sync (SRT) and async (AsyncSRT) accept paths: it accepts several connections in a row from the same listener and asserts the listener staysLISTENINGthroughout.Verified locally:
src/node-srt.ccchange and rebuilding the addon reproduces the bug: the listener's state goesBROKENright after the first accept, and the next connection attempt errors out (invalid listener socket ID value).Fixes #79
cc @birme