Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-11-22
22:55 • Closed ticket [2b6b0a5729]: writes accepted after non-blocking chan close write<... artifact: 9e463c5705 user: jan.nijtmans
2026-11-21
22:40
Fix [2b6b0a]: writes accepted after non-blocking chan close write check-in: 8ef086ecf6 user: jan.nijtmans tags: core-8-6-branch
15:01
Fix [2b6b0a]: writes accepted after non-blocking chan close write check-in: b111208765 user: jan.nijtmans tags: core-9-0-branch
2026-11-20
16:41 • Pending ticket [2b6b0a5729]: writes accepted after non-blocking chan close write... artifact: bc99893964 user: jan.nijtmans
16:40
Fix [2b6b0a]: writes accepted after non-blocking chan close write check-in: a98d8d4e44 user: jan.nijtmans tags: trunk, main
2026-10-16
21:29 • Ticket [2b6b0a5729] writes accepted after non-blocking chan close write stat... artifact: 8607a861af user: serhiy.storchaka
21:29
Fix [2b6b0a5729]: writes accepted after non-blocking chan close write. Tcl_GetChannelMode() does not... closed check-in: 9a8c807d9f user: serhiy.storchaka tags: chan-close-write-pending
21:22 • New ticket [2b6b0a5729] writes accepted after non-blocking chan close write. artifact: 7d7a6294d9 user: serhiy.storchaka

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.