Tcl Source Code

View Ticket
Login
2026-10-16
21:17 • Closed ticket [1329568fff]: socket -async and puts: Inadequate documentation... artifact: d89f277197 user: serhiy.storchaka
21:16 • Ticket [251f46655c] close of a pending socket -async fails and loses the buffere... artifact: c41312943f user: serhiy.storchaka
21:14
Fix [251f46655c]: close of a pending socket -async fails and loses the buffered output. Do not shut ... leaf check-in: a430d26e7c user: serhiy.storchaka tags: unix-async-close-pending
21:08 • Ticket [251f46655c] close of a pending socket -async fails and loses the buffere... artifact: b5fe37a4a9 user: serhiy.storchaka
20:59 • Ticket [251f46655c]: 2 changes artifact: 6a7b59dd02 user: serhiy.storchaka
20:59 • New ticket [251f46655c]. artifact: 389047f354 user: serhiy.storchaka

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.