<i>Why does FileCloseProc preserve standard descriptors during thread exit, but TcpCloseProc does not?</i>.
by
.
D 2026-10-28T10:28:20.984
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-plain
J comment We\sare\sinvestigating\san\sexit-time\sissue\sin\sa\sC++\sapplication\sembedding\sTcl\s8.6.8.\r\n\r\nSome\sC++\sstatic\sdestructors\swrite\sto\sstderr\safter\sTcl_Exit()\sstarts\sapplication\sshutdown.\sThe\sbehavior\sdepends\son\show\sthe\sapplication\sis\slaunched:\r\n\r\nLSF\sbsub\s-I:\sstdin,\sstdout\sand\sstderr\sare\sinherited\sINET\ssockets.\sTcl\swraps\sstdin\sand\sstderr\sas\sTCP\schannels.\sDuring\sshutdown,\sTcpCloseProc\scloses\sfd\s2\sbefore\sthe\sC++\sstatic\sdestructors\srun,\scausing\stheir\swrites\sto\sstderr\sto\sfail\swith\sEBADF.\r\nLSF\sbsub\s-Ip:\sthe\sstandard\sdescriptors\sare\sconnected\sto\sa\spseudo-terminal.\sThe\scorresponding\schannels\suse\sFileCloseProc,\swhich\spreserves\sstandard\sdescriptors\sduring\sthread\sexit.\sThe\sdestructor\smessages\sprint\ssuccessfully.\r\nIn\sthe\sTcl\sversion\swe\sare\susing,\sFileCloseProc\schecks\sTclInThreadExit()\sand\savoids\sclosing\sdescriptors\s0,\s1\sand\s2\sduring\sthread-exit\scleanup.\sHowever,\sTcpCloseProc\scloses\sits\ssocket\sdescriptors\swithout\san\sequivalent\scheck.\r\n\r\nWe\sconfirmed\sthe\sfollowing\sshutdown\spath\swith\sa\sdebugger:\r\nTcl_Exit\r\n\s\s→\sFinalizeThread\r\n\s\s\s\s→\sTclFinalizeIOSubsystem\r\n\s\s\s\s\s\s→\sChanClose\r\n\s\s\s\s\s\s\s\s→\sTcpCloseProc\r\n\s\s\s\s\s\s\s\s\s\s→\sclose(2)\r\nAt\sthis\spoint,\sTclInThreadExit()\sreturns\s1.\sLater,\sthe\sC++\sdestructor’s\swrite\sto\sfd\s2\sfails.\r\n\r\nCould\syou\splease\sclarify:\r\n\r\n1.\sIs\sthere\san\sintentional\sreason\sfor\spreserving\sstandard\sdescriptors\sin\sFileCloseProc\sbut\snot\sin\sTcpCloseProc?\r\n2.\sWould\sapplying\sthe\ssame\sthread-exit\scheck\sto\sstandard\ssocket\sdescriptors\sin\sTcpCloseProc\sbe\sappropriate,\sor\scould\sthat\saffect\ssocket\scleanup\ssemantics?\r\n3.\sHas\sthis\sbehavior\sbeen\saddressed\sin\sa\snewer\sTcl\srelease?\r\n4.\sIs\sthere\sa\srecommended\sapproach\sfor\san\sembedding\sapplication\sthat\sneeds\sstderr\sto\sremain\savailable\sto\sC++\sstatic\sdestructors\sduring\sshutdown?\r\n\r\nOur\sproposed\schange\swould\spreserve\sonly\sdescriptors\s0,\s1\sand\s2\sduring\sthread-exit\scleanup.\sOther\ssocket\sdescriptors,\sand\sexplicit\schannel\scloses\soutside\sthread\sexit,\swould\sretain\stheir\sexisting\sbehavior.\r\n\r\nThank\syou\sfor\syour\sguidance
J is_private 0
J login arvind29
J priority 5\sMedium
J private_contact 24b6332679e5f96732dab3b9d46f1f0d512b2551
J resolution None
J severity Critical
J status Open
J submitter arvind29
J subsystem 27.\sChannel\sTypes
J title Why\sdoes\sFileCloseProc\spreserve\sstandard\sdescriptors\sduring\sthread\sexit,\sbut\sTcpCloseProc\sdoes\snot?
J type Bug
K f739b95fdb1e8277f40fb42936d52b2116464ba2
U arvind29
Z 9af524787578915d74d7828a0a10386e