Fix stalled connections during session-key negotiation - #708
Open
nathansimony wants to merge 1 commit into
Open
nathansimony wants to merge 1 commit into
nathansimony wants to merge 1 commit into
Conversation
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.
Problem
When a protocol 3.4/3.5 device closes its TCP connection before session-key negotiation completes,
connect()can remain pending forever. The socketclosehandler callsdisconnect(), which returns early while_connectedis false, leavingconnectPromisecached. Subsequent callers receive the same unresolved promise.The socket timeout is also removed on TCP connection, before authentication completes, so a silent handshake has no deadline. A caller awaiting
connect()before scheduling its next retry can consequently stop retrying indefinitely.Change
_connectTimeoutas a deadline for the complete connection attempt, including session-key negotiation; clear it on success or cleanup.disconnectednotifications for connections that actually reached the connected state.The public options and retry policy are unchanged. This does not add automatic retries to TuyAPI; it allows callers' existing retry logic to run.
Validation
npm run coveragealso passes on 24.15.0._packetHandlercomplexity warning and no errors. The repository's older lint dependencies fail to start under Node.js 24 (util.isDate), so lint used Node.js 20.The original production outage is consistent with this failure mode, but its initial handshake was not captured; the regression tests independently demonstrate the library defect.