Skip to content

fix: connection lifecycle fixes for socket death and close - #9

Open
Dodothereal wants to merge 1 commit into
alexanderolvera:mainfrom
Dodothereal:fix/6-connection-lifecycle-connected-lies-afte
Open

fix: connection lifecycle fixes for socket death and close#9
Dodothereal wants to merge 1 commit into
alexanderolvera:mainfrom
Dodothereal:fix/6-connection-lifecycle-connected-lies-afte

Conversation

@Dodothereal

Copy link
Copy Markdown

fix: connection lifecycle fixes for socket death and close

Summary

Fixes the connection lifecycle issues where the connected flag remained true after socket death, and the close() method left internal buffers in a stale state. The fail() method now properly destroys the socket and resets connection state, while clear() clears buffers. The socket 'close' event listener is guarded to prevent double-failure callbacks.

Fixes #6

Changes

  • In fail(): destroy socket with error, set sock=null, shookHands=false, ready=null, and clear buffers.
  • In close(): clear buffers after closing socket.
  • In connect(): only call fail on 'close' event if socket is still open to avoid double-fail.

Testing

Built the project with npm run build and ran the existing test suite via node scripts/mock-server-test.js. All tests pass:

PASS  handshake
PASS  GetVersion decodes StringMessage
PASS  GetWorldInfo decodes nested NameInfo + fields
PASS  RunCommand captures TEXT frames
PASS  cached bind (second call works)

All protocol checks passed.

AI assistance disclosure

This contribution was produced by an autonomous AI coding agent (Claude Code) that @Dodothereal operates and monitors. @Dodothereal is accountable for it, will address review feedback promptly, and will close this PR immediately if this kind of contribution is unwelcome in this project. Commits carry an Assisted-by: Claude Code trailer.

- In fail(): destroy socket with error, set sock=null, shookHands=false, ready=null, and clear buffers.
- In close(): clear buffers after closing socket.
- In connect(): only call fail on 'close' event if socket is still open to avoid double-fail.

Fixes alexanderolvera#6

Assisted-by: Claude Code
Copilot AI review requested due to automatic review settings July 23, 2026 09:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

connection lifecycle: connected lies after socket death; desync and close() leave stale state

2 participants