Crash opening server sockets in more than one thread on Windows
Closed / Fixed31fc36fe475584527a11610105c03a9f4dca3e0cCreated 3 years agoUpdated 3 years ago
Descriptionmarkdown2023-10-21 05:49:29
With the thread package installed, http.test crashes with a NULL pointer exception. Call stack below - tsdPtr is NULL for whatever reason.
Tested on core-8-branch [12946b5cac] and head of thread-2-8-branch [6088b58218].
I presume that is the correct thread branch for 8.7, as opposed to the thread trunk.
Windows only.
tcl87.dll!Tcl_OpenTcpServerEx(Tcl_Interp * interp, const char * service, const char * myHost, unsigned int flags, int backlog, void(*)(void *, Tcl_Channel_ *, char *, int) acceptProc, void * acceptProcData) Line 2230
at d:\src\tcltk\core-8-branch\tcl\win\tclWinSock.c(2230)
tcl87.dll!Tcl_SocketObjCmd(void * dummy1465, Tcl_Interp * interp, int objc, Tcl_Obj * const * objv) Line 1654
at d:\src\tcltk\core-8-branch\tcl\generic\tclIOCmd.c(1654)
tcl87.dll!Dispatch(void * * data, Tcl_Interp * interp, int dummy4918) Line 4957
at d:\src\tcltk\core-8-branch\tcl\generic\tclBasic.c(4957)
tcl87.dll!TclNRRunCallbacks(Tcl_Interp * interp, int result, NRE_callback * rootPtr) Line 4996
at d:\src\tcltk\core-8-branch\tcl\generic\tclBasic.c(4996)
tcl87.dll!Tcl_EvalObjv(Tcl_Interp * interp, int objc, Tcl_Obj * const * objv, int flags) Line 4716
at d:\src\tcltk\core-8-branch\tcl\generic\tclBasic.c(4716)
tcl87.dll!TclEvalEx(Tcl_Interp * interp, const char * script, int numBytes, int flags, int line, int * clNextOuter, const char * outerScript) Line 5873
at d:\src\tcltk\core-8-branch\tcl\generic\tclBasic.c(5873)
tcl87.dll!Tcl_EvalEx(Tcl_Interp * interp, const char * script, int numBytes, int flags) Line 5537
at d:\src\tcltk\core-8-branch\tcl\generic\tclBasic.c(5537)
thread289.dll!ThreadSendEval(Tcl_Interp * interp, void * clientData) Line 1697
at d:\src\tcltk\thread\generic\threadCmd.c(1697)
thread289.dll!ThreadEventProc(Tcl_Event * evPtr, int mask) Line 3218
at d:\src\tcltk\thread\generic\threadCmd.c(3218)
tcl87.dll!Tcl_ServiceEvent(int flags) Line 710
at d:\src\tcltk\core-8-branch\tcl\generic\tclNotify.c(710)
tcl87.dll!Tcl_DoOneEvent(int flags) Line 1007
at d:\src\tcltk\core-8-branch\tcl\generic\tclNotify.c(1007)
thread289.dll!ThreadWait(Tcl_Interp * interp) Line 2963
at d:\src\tcltk\thread\generic\threadCmd.c(2963)
thread289.dll!ThreadWaitObjCmd(void * dummy, Tcl_Interp * interp, int objc, Tcl_Obj * const * objv) Line 1231
at d:\src\tcltk\thread\generic\threadCmd.c(1231)
tcl87.dll!Dispatch(void * * data, Tcl_Interp * interp, int dummy4918) Line 4957
at d:\src\tcltk\core-8-branch\tcl\generic\tclBasic.c(4957)
Referenced by3
ec84d4bf16Merge [b05d33be57ea5930]: Fix [31fc36fe47] - socket crash with multiple threads. check-in2024-08-22 21:06:49b05d33be57Merge 8.7 - Bug [31fc36fe47] - socket crash with multiple threads. check-in2023-10-21 14:51:14a387cc9310Bug [31fc36fe47] - socket crash with multiple threads. check-in2023-10-21 14:13:11
apnadkarniplain2023-10-21 10:58:47
Tcl 8.6 does not exhibit the issue (both with thread 2.8.9), quite possibly because the http test suite is very limited compared to 8.7. As for Tcl 9, the thread (3.0) package is not loadable so could not test (added to my things-to-look-at stack). In any case, with 8.7/2.8.9 the test suite crashes right away which should help with debugging. Unix builds in all configurations work without any issue so almost definitely a Windows issue only.
apnadkarniplain2023-10-21 11:24:24
So it turns out this has nothing to do with http except that it triggered the bug. The following suffices to crash ``` % socket -server accept 12345 sock000001334182C510 % package require Thread 2.8.9 % set tid [thread::create] tid0000000000004FF8 % thread::send $tid "socket -server accept 12345" couldn't open socket: address already in use % thread::send $tid "socket -server accept 12346" ...crash... ``` Requires sockets in both threads.
apnadkarniplain2023-10-21 14:59:46
Fixed for 8.7 and 9.0. 8.6 does not have this issue (socket initialization was refactored somewhere along the way introducing this bug).
Log in (anonymous is fine) to add a comment.