Skip to content

Commit fa0799b

Browse files
committed
fix: prevent double-close errors on tcp handle
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.
1 parent 93f8e48 commit fa0799b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

lua/claudecode/server/client.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,15 @@ function M.close_client(client, code, reason)
216216
local close_frame = frame.create_close_frame(code, reason)
217217
client.tcp_handle:write(close_frame, function()
218218
client.state = "closed"
219-
client.tcp_handle:close()
219+
if not client.tcp_handle:is_closing() then
220+
client.tcp_handle:close()
221+
end
220222
end)
221223
else
222224
client.state = "closed"
223-
client.tcp_handle:close()
225+
if not client.tcp_handle:is_closing() then
226+
client.tcp_handle:close()
227+
end
224228
end
225229

226230
client.state = "closing"

0 commit comments

Comments
 (0)