Tcl Source Code

View Ticket
Login
Ticket UUID: 251f46655c1a8b588b01f00f43c435c04ad10c75
Title: close of a pending socket -async fails and loses the buffered output
Type: Bug Created on: 2026-10-16 20:59:21
Submitter: serhiy.storchaka Assigned to:
Subsystem: 25. Channel System Severity: Minor
Priority: 5 Medium Last modified: 2026-10-16 21:16:36
Status: Open Closed by:
Resolution: None Closed on:
Version: 9.0.5, 9.1.0
Description:

On Unix, closing a [socket -async] channel while the connection is still being established loses the data written to it:

set s [socket -async $host $port]   ;# connect still pending
puts $s hello
close $s   ;# error: transport endpoint is not connected; the server gets nothing

The same happens for a non-blocking channel, where the error is also raised by close.

8.6 sends the data. Since [d5bc305ad2] Tcl_Close() always shuts down the read side before flushing, and TcpClose2Proc() calls shutdown(SHUT_RD) on the still connecting socket, which aborts the connect on Linux.

User Comments:
serhiy.storchaka added on 2026-10-16 21:16:36:

Proposed fix in branch unix-async-close-pending: TcpClose2Proc() does not shut down the read side while the connect is pending. Test socket-14.20. This also fixes [chan close $s read] on a pending socket, which aborted the connect even in 8.6.