writes accepted after non-blocking chan close write
Closed / Fixed2b6b0a57296aecf267d19554a6a0c6f2ac83efbcCreated 47 days agoUpdated 10 days ago
Descriptionwiki2026-10-16 21:22:15
After [chan close $chan write] on a non-blocking channel with output still queued, the channel stays writable until the background flush finishes: [puts] is accepted and the data is sent after the half-close.
set p [open |[list [info nameofexecutable] child.tcl] r+] ;# child reads stdin later fconfigure $p -blocking 0 puts -nonewline $p [string repeat a 1000000] chan close $p write ;# returns at once, output still pending puts $p AFTER ;# no error; the child receives "AFTER"
A blocking channel gives "channel wasn't opened for writing". CloseWrite() sets CHANNEL_CLOSEDWRITE, but TCL_WRITABLE is reset only when the flush completes (CloseChannelPart), and neither Tcl_GetChannelMode() nor CheckChannelErrors() looks at CHANNEL_CLOSEDWRITE. Seen with pipes and sockets.
Referenced by1
9a8c807d9fFix [2b6b0a5729]: writes accepted after non-blocking chan close write. Tcl_GetChannelMode() does not report the write side once CHANNEL_CLOSEDWRITE is set, while the queued output is still flushed in the background. check-in2026-10-16 21:29:10
serhiy.storchakawiki2026-10-16 21:29:43
Proposed fix in branch chan-close-write-pending: Tcl_GetChannelMode() does not report the write side once it is closed, so [puts] and a second [chan close $chan write] fail as for a blocking channel; the queued output is still flushed. Test iocmd-7.6.
jan.nijtmanswiki2026-11-20 16:41:51
Merged to [trunk].
jan.nijtmanswiki2026-11-22 22:55:52
Merged to [trunk], core-9-0-branch and core-8-6-branch
Many thanks!
Log in (anonymous is fine) to add a comment.