Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: df52774e8fef7e6f11928abc3986b725bbc37ccb
Ticket: 3545365fffffffffffffffffffffffffffffffff
Crash in io-29.33b (no implicit flush of nonblocking on exit
User & Date: twylite on 2012-07-25 00:57:02
Changes

  1. icomment:
    No fix yet.  I've had to delve deeper into how this file works, and it's confirming my suspicions.  The pipe handles are not opened with FILE_FLAG_OVERLAPPED, which means they're blocking.  This allows for simple blocking operations in the main thread when (! PIPE_ASYNC), but means that when we're in async mode the write is transferred to the writeThread where WriteFile() is blocking.
    
    Enter http://msdn.microsoft.com/en-us/library/windows/desktop/aa365683(v=vs.85).aspx, which confirms that a CloseHandle() in one thread will not in fact interrupt synchronous IO on the handle in another thread.  
    
    On Windows 2008 or Windows 7 we can use CancelSynchronousIo(pipePtr->writeThread) before the CloseHandle to remedy the situation (io-29.33b run 100 times in a loop, all pass).  But there is no equivalent function pre-Win2008.
    
    If I put a Tcl_Panic in the (WriteFile() == FALSE) branch of the PipeWriterThread, I never hit it, unless I do a CancelSynchronousIo.
    
    A Tcl_Panic after the WaitForSingleObject(pipePtr->writable, INFINITE); in PipeClose2Proc() often reveals that the writeThread is gone.  This means that the SetEvent(pipePtr->stopWriter) has woken the thread from a WaitForMultipleObjects, and the thread has then terminated (without signalling infoPtr->writable, because it doesn't do that if woken by stopWriter).  Adding a signal to prevent this specific block makes the detection window for the bug narrower, but doesn't solve it.
    
    According to my current understanding there is no solution without a redesign to allow WriteFile to be non-blocking in the writeThread.
    
    I'll continue looking at the problem tomorrow, and see if I can confirm all these details, and if there is a workable solution (or just attempt to minimize the bug window).
    
    
    
  2. login: "twylite"
  3. mimetype: "text/plain"
  4. username: "twylite"