<i>Windows 8.6: under ephemeral port exhaustion, sockets get disabled for the whole process and Tcl sometimes crashes</i>.
by
.
D 2026-10-23T07:07:25.705
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment On\sWindows,\swhen\sthe\sephemeral\sTCP\sports\sare\sexhausted,\sTcl\s8.6\sdisables\ssockets\sfor\sthe\swhole\sprocess\sinstead\sof\sreporting\sthe\serror,\sand\ssometimes\scrashes.\n\nReproduced\son\sWindows\s11\swith\sthe\s8.6\stip\s(8.6.18,\sThread\s2.8.13).\sEach\sthread\sopens\sa\sserver\ssocket\son\sa\sfree\sport\sof\s127.0.0.1\sand\sa\sclient\sconnection\sto\sit,\sthen\sexits\swith\sboth\sopen:\n\n<verbatim>\npackage\srequire\sThread\nset\sscript\s{\n\s\s\s\sset\ssrv\s[socket\s-server\s{apply\s{{c\sa\sp}\s{set\s::c\s$c}}}\s-myaddr\s127.0.0.1\s0]\n\s\s\s\sset\scli\s[socket\s127.0.0.1\s[lindex\s[fconfigure\s$srv\s-sockname]\s2]]\n\s\s\s\supdate\n}\nfor\s{set\si\s0}\s{$i\s<\s1000}\s{incr\si}\s{\n\s\s\s\sthread::join\s[thread::create\s-joinable\s$script]\n}\n</verbatim>\n\nRunning\sit\srepeatedly\sfills\sthe\sdynamic\sport\srange\swith\sTIME_WAIT\sconnections\s(about\s16300\sof\s16384).\sThen\sthe\sfirst\serror\sis\s<tt>couldn't\sopen\ssocket:\saddress\salready\sin\suse</tt>,\sas\sexpected.\sBut\s8.6\sthen\sfails\swith\s<tt>sockets\sare\snot\savailable\son\sthis\ssystem</tt>\sor\s<tt>winsock\sis\snot\sinitialized</tt>,\sin\severy\sthread\sincluding\sthe\smain\sone,\sfor\sthe\srest\sof\sthe\sprocess.\sIn\s5\sof\s40\sruns\sof\sa\sstress\sscript\sthe\sprocess\sfailed\sthis\sway,\s2\sof\sthem\swith\sa\scrash\s(SIGSEGV).\sWithout\sport\sexhaustion\sit\sruns\sclean.\n\n9.0\sand\s9.1\sin\sthe\ssame\sstate\sjust\sreport\s<tt>address\salready\sin\suse</tt>\s(40\sof\s40\sruns\swithout\sfailure\seach).\n\nPossible\scause:\s<tt>InitSockets()</tt>\sin\swin/tclWinSock.c\sof\s8.6\ssets\sthe\sglobal\s<tt>initialized</tt>\sto\s-1\swhen\sthe\sper-thread\ssetup\sfails\sin\sone\sthread,\swhich\sdisables\ssockets\sin\sall\sthreads.\s8.7\sand\s9.0\sreworked\sthis\sinitialization.\sBackporting\s[a36f76eb6b]\s(for\s[40b1814b93])\sto\s8.6\sdid\snot\shelp\s(4\sof\s40\sruns\sstill\sfailed,\s2\scrashes).\sThe\scrash\smay\sbe\srelated\sto\s[06f19cc401],\sfixed\sonly\son\smain.
J foundin 8.6.18
J is_private 0
J login serhiy.storchaka
J priority 5\sMedium
J resolution None
J severity Important
J status Open
J submitter serhiy.storchaka
J subsystem 27.\sChannel\sTypes
J title Windows\s8.6:\sunder\sephemeral\sport\sexhaustion,\ssockets\sget\sdisabled\sfor\sthe\swhole\sprocess\sand\sTcl\ssometimes\scrashes
J type Bug
K 72d1c8c271771764d340ce7e75c142f63048a7ad
U serhiy.storchaka
Z 41ca1b11d9dca67522438f49892ea095