Artifacts Associated With Ticket 653218ffffffffff
Ticket change [4333706460] (rid 116514) by schroedter on 2002-12-13 11:54:58:
- assignee initialized to: "andreas_kupries"
- cmimetype initialized to: "text/plain"
- comment initialized to:
If there is pending BG output for a non-blocking channel then Tcl_DriverCloseProc() is not called when the 'close' command is invoked. That can be seen from generic/tclIO.c : Tcl_Unregister_Channel(): if (!(statePtr->flags & BG_FLUSH_SCHEDULED)) { ... This can be very bad if channel's output is stalled, e.g. a serial port blocked by handshake: % puts "Tcl $tcl_patchLevel" Tcl 8.4b1 % set chan [open com1: r+] fileaaf550 % fconfigure $chan -buffering none -blocking 0 % fconfigure $chan -mode 1200,n,8,1 -handshake rtscts % ### 2 outputs: "hello world" \x0D\x0A, BG_FLUSH % puts $chan "hello world" % puts "Queue: [fconfigure $chan -queue]" Queue: 0 13 % after 1000 % puts "Queue: [fconfigure $chan -queue]" Queue: 0 13 % close $chan % set chan [open com1: r+] couldn't open "com1:": permission denied % This problem occurs also for slow output without handshake: % puts "Tcl $tcl_patchLevel" Tcl 8.4b1 % set chan [open com1: r+] fileaaf768 % fconfigure $chan -buffering none -blocking 0 % # Explicitely reset handshake=none % fconfigure $chan -mode 1200,n,8,1 -handshake none % puts $chan "hello world" % puts $chan "hello world" % close $chan % set chan [open com1: r+] couldn't open "com1:": permission denied For Tcl < 8.4. this has never been observed for serial ports, because serial output has already been blocking. - foundin initialized to: "obsolete: 8.4.1"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "schroedter"
- subsystem initialized to: "25. Channel System"
- title initialized to: "Channels CloseProc() not called on close"
- type initialized to: "Bug"
Ticket change [46695c69c6] (rid 99514) by schroedter on 2002-12-13 18:58:29:
- icomment:
Logged In: YES user_id=99573 This bahaviour may be interpretet not as a bug, but as a feature of the channel system. But then we need an additional option [fconfigure $chan -flushonclose 0] (default=1) for channels like serial ports. - login: "schroedter"
- mimetype: "text/plain"
- username: "schroedter"
- icomment:
Ticket change [ecda7f38da] (rid 103778) by dkf on 2002-12-13 20:17:39:
- icomment:
Logged In: YES user_id=79902 When I have time (maybe, just maybe, over Xmas) I'll be advancing a TIP on behaviour-on-close of serial channels.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [65cb6e2bfc] (rid 102605) by dgp on 2002-12-13 20:51:55:
- icomment:
Logged In: YES user_id=80530 Is this related to FR 525783 ?
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [b0d95fe8d8] (rid 98050) by schroedter on 2002-12-13 21:14:31:
- icomment:
Logged In: YES user_id=99573 IMO not. [ 526163 ] tty not reset on exit is related to the (requested) change made by TIP#35, not to restore the original TTY settings on close, so that tcl can be used as a simple 'stty' substitute. This stuff is not yet finally removed - see the comment in tclUnixChan.c, ttyCloseProc().
- login: "schroedter"
- mimetype: "text/plain"
- username: "schroedter"
- icomment:
Ticket change [fd94c4c9e8] (rid 108427) by andreas_kupries on 2003-01-07 05:52:45:
- icomment:
Logged In: YES user_id=75003 Note: If BG_FLUSH_SCHEDULED is set the channel cannot be closed completely. There is a BackGround-FLUSH of data active. The channel won't be visible at the script level anymore, but the data structures remain until the flush is completed. After that happend the close proc is called and the structures are cleaned up completely. This is only for a non-blocking channel. To get 'flushonclose' behaviour just set the channel to - blocking 1. Of course, this may stall the [close] at the tcl level if the serial port itself is stalled.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [1ab2d5312b] (rid 123024) by schroedter on 2003-01-07 15:28:10:
- icomment:
Logged In: YES user_id=99573 Yes, what you say emphasizes that Tcl needs a mechanism to close a stalled serial channel by discarding all currently pending output.
- login: "schroedter"
- mimetype: "text/plain"
- username: "schroedter"
- icomment:
Ticket change [b7d2e6fea8] (rid 128861) by dkf on 2003-01-07 17:59:04:
- icomment:
Logged In: YES user_id=79902 There are several possible desired behaviours for what should happen on closing of a serial channel, but I think these are the interesting cases: wait until all OS buffers are empty and reset to initial state discard all pending output (including OS level) and reset to init. leave channel in *current* state (I'll not specify what happens to the OS buffers in that last case as I believe that typically in that case, there won't be much data in the buffers anyway!) IIRC, right now we just support the first of those, and we know that selection of the right behaviour can't be done automatically (we don't want to discard debug info!) so that calls for a suitable [fconfigure] option. Which means a TIP. Which I've not had time to write. (And I'm not certain how -blocking interacts with this; the buffers in question are in the OS, not Tcl.)
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [643fb62ba9] (rid 92725) by schroedter on 2003-01-08 13:52:51:
- icomment:
Logged In: YES user_id=99573 For blocking channels no changes are necessary. For non-blocking channels the current behaviour is to put the channel to *blocking* mode, wait until all Tcl output buffers are done and only then call Tcl_DriverCloseProc(). If there would be a non-default [fconfigure -discardonclose 1] option the channel system should 1. *Not* make the channel blocking. 2. Discard all pending output in Tcl buffers. 3. Immediately call Tcl_DriverCloseProc(). The serial SerialCloseProc() is responsive for the OS-level output. So SerialCloseProc() should also check for the [fconfigure -discardonclose 1] flag and discard OS-level output. I could write the TIP and implement the the changes in the serial drivers SerialCloseProc() for Windows & Posix. But I do not feel skilled for the changes in the general channel system.
- login: "schroedter"
- mimetype: "text/plain"
- username: "schroedter"
- icomment:
Ticket change [6753ec15a4] (rid 102880) by dkf on 2003-10-16 20:59:24:
- resolution changed to: "Remind"
Ticket change [005ad727f2] (rid 258324) by serhiy.storchaka on 2026-10-16 21:49:57:
- icomment:
The deferred close is by design (see close(n)). Testing this found that on Linux in 8.7 and later a background flush to a pipe whose reader has exited never ends: [7aa8fd34c4].
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Invalid"
- status changed to: "Closed"
- icomment:
Ticket change [20bd9150f8] (rid 259953) by serhiy.storchaka on 2026-10-22 17:19:27:
- closedate changed to: "2461330.4096968286"
- closer changed to: "serhiy.storchaka"
- login: "serhiy.storchaka"