Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 12abe7823499d448f67039f9422666c1adff9ee20693a9c021cbdc49bc987c2c
Ticket: 72814c7ef162e03e4261a0236f4f03efc8c51372
Tcl 8.6.7 - Tcl 8.6.13 socket.test hang intermittently on Windows 10
User & Date: apnadkarni on 2023-10-22 15:26:24
Changes

  1. icomment:
    Reproducing by running the test suite in a loop, here is what I see. The main thread is blocked in [TclPipeThreadStop](https://core.tcl-lang.org/tcl/file?ci=584bb57e0b7ce85b&name=win/tclWinPipe.c&ln=3600) waiting for the console reader thread to exit. The stack: 
    
    ```
    ntdll.dll!00007ff99256e234()
    KernelBase.dll!00007ff98ff957c2()
    tcl86t.dll!TclPipeThreadStop(TclPipeThreadInfo * * pipeTIPtr, void * hThread) Line 3600
    	at d:\src\tcltk\core-8-6-branch\tcl\win\tclWinPipe.c(3600)
    tcl86t.dll!ConsoleCloseProc(void * instanceData, Tcl_Interp * interp) Line 547
    	at d:\src\tcltk\core-8-6-branch\tcl\win\tclWinConsole.c(547)
    tcl86t.dll!ChanClose(Channel * chanPtr, Tcl_Interp * interp) Line 362
    	at d:\src\tcltk\core-8-6-branch\tcl\generic\tclIO.c(362)
    tcl86t.dll!TclFinalizeIOSubsystem() Line 677
    	at d:\src\tcltk\core-8-6-branch\tcl\generic\tclIO.c(677)
    tcl86t.dll!FinalizeThread(int quick) Line 1320
    	at d:\src\tcltk\core-8-6-branch\tcl\generic\tclEvent.c(1320)
    tcl86t.dll!Tcl_Exit(int status) Line 995
    	at d:\src\tcltk\core-8-6-branch\tcl\generic\tclEvent.c(995)
    tcl86t.dll!Tcl_ExitObjCmd(void * dummy, Tcl_Interp * interp, int objc, Tcl_Obj * const * objv) Line 1036
    	at d:\src\tcltk\core-8-6-branch\tcl\generic\tclCmdAH.c(1036)
    tcl86t.dll!Dispatch(void * * data, Tcl_Interp * interp, int result) Line 4503
    	at d:\src\tcltk\core-8-6-branch\tcl\generic\tclBasic.c(4503)
    tcl86t.dll!TclNRRunCallbacks(Tcl_Interp * interp, int result, NRE_callback * rootPtr) Line 4538
    	at d:\src\tcltk\core-8-6-branch\tcl\generic\tclBasic.c(4538)
    tcl86t.dll!TclEvalObjEx(Tcl_Interp * interp, Tcl_Obj * objPtr, int flags, const CmdFrame * invoker, int word) Line 6104
    	at d:\src\tcltk\core-8-6-branch\tcl\generic\tclBasic.c(6104)
    
    ```
    
    The ConsoleReader thread is blocked on [ReadConsole](https://core.tcl-lang.org/tcl/file?ci=584bb57e0b7ce85b&name=win/tclWinConsole.c&ln=225) with the stack
    
    ```
    ntdll.dll!00007ff99256d0c4()
    KernelBase.dll!00007ff98fe87861()
    KernelBase.dll!00007ff98ff90e4b()
    KernelBase.dll!00007ff98ff90eda()
    tcl86t.dll!ReadConsoleBytes(void * hConsole, void * lpBuffer, unsigned long nbytes, unsigned long * nbytesread) Line 225
    	at d:\src\tcltk\core-8-6-branch\tcl\win\tclWinConsole.c(225)
    tcl86t.dll!ConsoleReaderThread(void * arg) Line 1150
    	at d:\src\tcltk\core-8-6-branch\tcl\win\tclWinConsole.c(1150)
    kernel32.dll!00007ff9911b7344()
    ntdll.dll!00007ff9925226b1()
    
    ```
    
    The above are the only two threads running.
    
    In my case at least, hitting Return a few times unblocks the ConsoleReader thread allowing the process to exit.
    
    First, I do not think this is an issue with sockets at all, the socket tests just trigger the bug related to finalization of the console threads.
    
    Second, I do not see how the synchronization during finalization is supposed to work. What unblocks the ReadConsole call shown on the stack above? On older systems (like XP, 2003, which 8.6 supports) , the Win32 CancelSyncIo api does not exist. Second, even if it did, there is a race condition, however small, between the CancelSyncIO in the main thread and the ReadConsole in the console reader thread. If the latter happens after the former but before the close handle (in the main thread) it will still block. 
    
    Third, even if it unblocks, afaict it will see a ERROR_OPERATION_ABORTED and just loop around and block again.
    
    Sergey is of course far more competent is these matters and hopefully he can find a solution.
    
    Note the windows console in 8.7 is completely rewritten so in theory should not be affected by this. It would be useful if @szhong could test 8.7 on his system to verify it is not subject to this "hang".
    
  2. login: "apnadkarni"
  3. mimetype: "text/x-markdown"