Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: a183910f7d82a8276df808bd6f51370b3722b688
Ticket: 3545365fffffffffffffffffffffffffffffffff
Crash in io-29.33b (no implicit flush of nonblocking on exit
User & Date: twylite on 2012-07-24 22:48:04
Changes

  1. icomment:
    Intermittent failures in io-29.33b confirmed.  Cause not known.  About 1 in 5 times I run io-29.33b on its own it will fail.  I've made a io-29.33c that reports the actual time delta (and always fails), and I get results like: 29, 28, 35, 29, 2032, 29, ...
    
    I've also tried a completely different approach, which is to signal the PipeWriterThread to stop, and allow the WriteFile() loop in that thread to be interrupted by the signal.  I still get the intermittent failures in io-29.33b.  Changing the WriteFile() to write at most 4096 bytes at a time (as in the diff below) doesn't help (although it does seem to make the failures less frequent, maybe).
    
    
    --- tclWinPipe.c
    +++ tclWinPipe.c
    @@ -1872,10 +1872,17 @@
            pipePtr->readFile = NULL;
         }
         if ((!flags || flags & TCL_CLOSE_WRITE)
                && (pipePtr->writeFile != NULL)) {
            if (pipePtr->writeThread) {
    +               /*
    +                * Set the stop event so that if the writer thread is blocked
    +                * in PipeWriterThread it will exit cleanly.
    +                */
    +
    +               SetEvent(pipePtr->stopWriter);
    +
                /*
                 * Wait for the writer thread to finish the current buffer, then
                 * terminate the thread and close the handles. If the channel is
                 * nonblocking, there should be no pending write operations.
                 */
    @@ -1888,17 +1895,10 @@
                 */
    
                GetExitCodeThread(pipePtr->writeThread, &exitCode);
    
                if (exitCode == STILL_ACTIVE) {
    -               /*
    -                * Set the stop event so that if the reader thread is blocked
    -                * in PipeReaderThread on WaitForMultipleEvents, it will exit
    -                * cleanly.
    -                */
    -
    -               SetEvent(pipePtr->stopWriter);
    
                    /*
                     * Wait at most 20 milliseconds for the reader thread to
                     * close.
                     */
    @@ -2953,12 +2953,12 @@
    
            /*
             * Loop until all of the bytes are written or an error occurs.
             */
    
    -       while (toWrite > 0) {
    -           if (WriteFile(handle, buf, toWrite, &count, NULL) == FALSE) {
    +       while (toWrite > 0 && (WAIT_OBJECT_0 != WaitForMultipleObjects(1, wEvents, FALSE, 0)) ) {
    +           if (WriteFile(handle, buf, min(toWrite, 4096), &count, NULL) == FALSE) {
                    infoPtr->writeError = GetLastError();
                    done = 1;
                    break;
                } else {
                    toWrite -= count;
    
    
    
  2. login: "twylite"
  3. mimetype: "text/plain"
  4. username: "twylite"