Artifacts Associated With Ticket f739b95fdb
Ticket change [f90d5e2b8a] (rid 260713) by arvind29 on 2026-10-28 10:28:20:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-plain"
- comment initialized to:
We are investigating an exit-time issue in a C++ application embedding Tcl 8.6.8. Some C++ static destructors write to stderr after Tcl_Exit() starts application shutdown. The behavior depends on how the application is launched: LSF bsub -I: stdin, stdout and stderr are inherited INET sockets. Tcl wraps stdin and stderr as TCP channels. During shutdown, TcpCloseProc closes fd 2 before the C++ static destructors run, causing their writes to stderr to fail with EBADF. LSF bsub -Ip: the standard descriptors are connected to a pseudo-terminal. The corresponding channels use FileCloseProc, which preserves standard descriptors during thread exit. The destructor messages print successfully. In the Tcl version we are using, FileCloseProc checks TclInThreadExit() and avoids closing descriptors 0, 1 and 2 during thread-exit cleanup. However, TcpCloseProc closes its socket descriptors without an equivalent check. We confirmed the following shutdown path with a debugger: Tcl_Exit → FinalizeThread → TclFinalizeIOSubsystem → ChanClose → TcpCloseProc → close(2) At this point, TclInThreadExit() returns 1. Later, the C++ destructor’s write to fd 2 fails. Could you please clarify: 1. Is there an intentional reason for preserving standard descriptors in FileCloseProc but not in TcpCloseProc? 2. Would applying the same thread-exit check to standard socket descriptors in TcpCloseProc be appropriate, or could that affect socket cleanup semantics? 3. Has this behavior been addressed in a newer Tcl release? 4. Is there a recommended approach for an embedding application that needs stderr to remain available to C++ static destructors during shutdown? Our proposed change would preserve only descriptors 0, 1 and 2 during thread-exit cleanup. Other socket descriptors, and explicit channel closes outside thread exit, would retain their existing behavior. Thank you for your guidance - is_private initialized to: "0"
- login: "arvind29"
- priority initialized to: "5 Medium"
- private_contact initialized to: "24b6332679e5f96732dab3b9d46f1f0d512b2551"
- resolution initialized to: "None"
- severity initialized to: "Critical"
- status initialized to: "Open"
- submitter initialized to: "arvind29"
- subsystem initialized to: "27. Channel Types"
- title initialized to:
Why does FileCloseProc preserve standard descriptors during thread exit, but TcpCloseProc does not?
- type initialized to: "Bug"
Ticket change [d85c0e0bac] (rid 260714) by arvind29 on 2026-10-28 10:28:37:
- login: "arvind29"
- mimetype: "text/plain"
- priority changed to: "7 High"
Ticket change [0ffd9d8abf] (rid 260747) by arvind29 on 2026-10-28 14:43:26:
- foundin changed to: "8.6.8"
- login: "arvind29"
- mimetype: "text/plain"
Ticket change [b8097d6449] (rid 260823) by apnadkarni on 2026-10-30 06:22:45:
- icomment:
Couple of comments, mostly so you don't feel ignored :-) But I'm afraid will not help you much. I don't think the folks who originally wrote the code are involved in active core development any more so you are unlikely to get a definitive answer right away. Someone, perhaps me, will eventually take a look, but it is simply not a high priority and engineering time is very limited. Tcl 8.6.8 is way way old. Any fixes will not happen on 8.6 which is EOL so you should consider moving to 9.0 which has been out for a while now. Sorry for the bad news.
- login: "apnadkarni"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [10462f2652] (rid 260824) by arvind29 on 2026-10-30 06:48:20:
- icomment:
Thanks for the response. I checked Tcl 9.0.0 as suggested, but the same behavior is present there as well. Could you please confirm whether the difference between FileCloseProc and TcpCloseProc is intentional?
- login: "arvind29"
- mimetype: "text/plain"
- icomment: