Skip to content

Conversation

@Vvkmnn
Copy link

@Vvkmnn Vvkmnn commented Jan 5, 2026

Problem

When a connection is interrupted during an async write, the callback at client.lua:219 can attempt to close a handle that's already closing, causing:

handle 0x... is already closing

Root Cause

tcp.lua:161-162 correctly guards with is_closing():

if not client.tcp_handle:is_closing() then
  client.tcp_handle:close()
end

But client.lua:219,223 doesn't use this guard.

Fix

Add the same is_closing() check to client.lua to match the existing pattern.

Testing

  • Reproduced error by rapidly toggling Claude Code connection
  • Error no longer occurs after fix

When a connection is interrupted during an async write, the callback
can attempt to close a handle that's already closing, causing:
  handle 0x... is already closing

tcp.lua:161-162 correctly guards with is_closing():
  if not client.tcp_handle:is_closing() then
    client.tcp_handle:close()
  end

But client.lua:219,223 was missing this guard. Added the same defensive
check to prevent the race condition.
@Vvkmnn Vvkmnn force-pushed the fix/handle-double-close branch from 0b3bbe0 to fa0799b Compare January 5, 2026 05:52
@Vvkmnn Vvkmnn changed the title fix(server): guard against double-close on tcp handle fix: prevent double-close errors on tcp handle Jan 5, 2026
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.

1 participant