Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 24c253aac3713a8a78665ffcbdcde5d3b8c4e1d0
Ticket: 947693ffffffffffffffffffffffffffffffffff
Closing a non-blocking pipe can block on Win
User & Date: stevebold on 2004-05-04 13:37:46
Changes

  1. assignee changed to: "andreas_kupries"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    
    If I create a command channel and configure it as non-
    blocking,what should
    happen if I close the channel while the child process 
    continues to run?
    It seems reasonable that a non-blocking channel should 
    not block on close,
    and the manual states that flushing for a non-blocking 
    channel occurs in
    the background. I admit it does not explicitly state that 
    close cannot block in
    such a case. 
    
    The effect I am seeing using is that on Solaris 2.8 close 
    does return
    immediately but on Windows XP it blocks.
    
    The traceback at which it blocks is the following:
    
       WaitForSingleObject
       Tcl_WaitPid(Tcl_Pid_ * 0x00000790, int * 0x0026f1c4, 
    int 0) line 2537
       TclCleanupChildren(Tcl_Interp * 0x00979788, int 1, 
    Tcl_Pid_ * * 0x00996240, Tcl_Channel_ * 0x00995770) 
    line 294 + 21 bytes
       PipeClose2Proc(void * 0x00996338, Tcl_Interp * 
    0x00979788, int 0) line 2065 + 27 bytes
       CloseChannel(Tcl_Interp * 0x00979788, Channel * 
    0x00994c28, int 0) line 2277 + 22 bytes
       FlushChannel(Tcl_Interp * 0x00979788, Channel * 
    0x00994c28, int 0) line 2182 + 17 bytes
       Tcl_Close(Tcl_Interp * 0x00979788, Tcl_Channel_ * 
    0x00994c28) line 2582 + 15 bytes
       Tcl_UnregisterChannel(Tcl_Interp * 0x00979788, 
    Tcl_Channel_ * 0x00994c28) line 847 + 13 bytes
       Tcl_CloseObjCmd(void * 0x00000000, Tcl_Interp * 
    0x00979788, int 2, Tcl_Obj * const * 0x0097a964) line 
    544 + 13 bytes
       TclEvalObjvInternal(Tcl_Interp * 0x00979788, int 2, 
    Tcl_Obj * const * 0x0097a964, const char * 
    0x00000000, int 0, int 0) line 3084 + 25 bytes
       TclExecuteByteCode(Tcl_Interp * 0x00979788, 
    ByteCode * 0x00995900) line 1401 + 33 bytes
       TclCompEvalObj(Tcl_Interp * 0x00979788, Tcl_Obj * 
    0x00993570) line 980 + 13 bytes
       Tcl_EvalObjEx(Tcl_Interp * 0x00979788, Tcl_Obj * 
    0x00993570, int 0) line 4004 + 13 bytes
       Tcl_CatchObjCmd(void * 0x00000000, Tcl_Interp * 
    0x00979788, int 2, Tcl_Obj * const * 0x0026fb58) line 
    254 + 18 bytes
       TclEvalObjvInternal(Tcl_Interp * 0x00979788, int 2, 
    Tcl_Obj * const * 0x0026fb58, const char * 
    0x00992471, int 17, int 0) line 3084 + 25 bytes
       Tcl_EvalEx(Tcl_Interp * 0x00979788, const char * 
    0x00992278, int 522, int 0) line 3674 + 36 bytes
       Tcl_FSEvalFile(Tcl_Interp * 0x00979788, Tcl_Obj * 
    0x00993ac8) line 1603 + 19 bytes
       Tcl_Main(int 1, char * * 0x00976cac, int (Tcl_Interp 
    *)* 0x00401005 _Tcl_AppInit) line 292 + 18 bytes
       main() line 117 + 19 bytes
       TCLSH84! mainCRTStartup + 227 bytes
       KERNEL32! 77e7eb69()
    
    Note that, even though the channel is non-blocking, 
    TclCleanupChildren()
    calls Tcl_WaitPid() passing with argument options set to 
    0, i.e. the WNOHANG
    bit is clear so Tcl_WaitPid() does block.
    
    I originally encountered this problem with an rsh 
    command that blocks.
    However, I can get the same effect just starting a 
    tclsh. My test script
    is as follows:
    
    # Start test script
    
    proc getData {f} {
       if {[eof $f]} {
          set ::runFinished 1
          after cancel $::runTimeoutId
          return
       }
    
       puts "getData [gets $f]"
    }
    
    
    proc runFailed {args} {
       set ::runFinished 1
       puts "runFailed $args"
    }
    
    set timeout 5
    set ::runData ""
    
    # Originally doing this with an 'rsh' command that failed 
    to terminate.
    # set cmd "rsh dv45ixl ls"
    
    # For simplicity, can just start an interactive tclsh, this 
    waits
    # for a command on stdin so it also hangs.
    set cmd "tclsh84"
    
    puts "Starting cmd $cmd"
    set f [open "|$cmd"]
    fconfigure $f -blocking 0
    fileevent $f readable "getData $f"
    set ::runTimeoutId [after [expr $timeout * 1000] 
    runFailed $cmd]
    vwait runFinished
    unset ::runFinished
    
    puts "closing command channel"
    catch {close $f}
    puts "Command channel closed"
    
    # End test script
    
    I originally encountered this using my own build of Tcl 
    8.4.3 and the traceback relates to this version.
    I have also reproduced the problem using ActiveTcl 
    8.4.6.
    
    
  4. foundin changed to: "obsolete: 8.4.6"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "stevebold"
  9. subsystem changed to: "25. Channel System"
  10. title changed to: "Close on non-blocking channel can block"
  11. type changed to: "Bug"