Skip to content
Tcl Source Code History Of Ticket 947693ffffffffff
Login

History Of Ticket 947693ffffffffff

Artifacts Associated With Ticket 947693ffffffffff

  1. Ticket change [24c253aac3] (rid 131162) by stevebold on 2004-05-04 13:37:46:

    1. assignee initialized to: "andreas_kupries"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized 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 initialized to: "obsolete: 8.4.6"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "stevebold"
    9. subsystem initialized to: "25. Channel System"
    10. title initialized to: "Close on non-blocking channel can block"
    11. type initialized to: "Bug"
  2. Ticket change [7d80b2129b] (rid 97251) by davygrvy on 2004-06-01 15:10:53:

    1. icomment:
      Logged In: YES 
      user_id=7549
      
      Should Tcl_WaitPid be called with WNOHANG when the 
      channel is non-blocking?
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  3. Ticket change [8eb19fc9bf] (rid 120155) by stevebold on 2004-06-02 23:23:54:

    1. icomment:
      Logged In: YES 
      user_id=810219
      
      For comparison, using 8.4.3 on Solaris 2.8, waitpid() is called
      at the following stack trace:
      
      =>[1] waitpid(0x38b5, 0xffbee17c, 0x40, 0x0, 0x0, 0x0), at 
      0xff21a418 
        [2] Tcl_WaitPid(0x38b5, 0xffbee17c, 0x40, 0x38b5, 0x0, 
      0x0), at 0x97b58 
        [3] Tcl_ReapDetachedProcs(0xf80d0, 0xc0564, 0xc0564, 
      0x0, 0x21d9c, 0x9782c), at 0x898a8 
        [4] PipeCloseProc(0xf3088, 0xd4520, 0x0, 0x0, 0xde080, 
      0xdd7d8), at 0x978f8 
        [5] CloseChannel(0xd23f8, 0xe03b0, 0x0, 0xc0564, 0xe40f8, 
      0xd4520), at 0x7202c 
        [6] FlushChannel(0xd4520, 0x0, 0x0, 0xe40f8, 0x0, 
      0xe03b0), at 0x71f0c 
        [7] Tcl_Close(0x0, 0xe03b0, 0xc0564, 0xe03b0, 0xe40f8, 
      0xd4520), at 0x72430 
        [8] Tcl_UnregisterChannel(0xd4520, 0xe03b0, 0xe40f8, 
      0xc0564, 0xf80f0, 0xc0564), at 0x710e4 
        [9] Tcl_CloseObjCmd(0x0, 0xd4520, 0x2, 0xd7704, 0x791fc, 
      0xe4f08), at 0x79268 
        [10] TclEvalObjvInternal(0xd4520, 0x0, 0x0, 0x0, 0x0, 0x0), 
      at 0x329b0 
        [11] TclExecuteByteCode(0xd4520, 0xc355c, 0xc3564, 
      0xde0ed, 0x0, 0xd7704), at 0x5e83c 
        [12] TclCompEvalObj(0x0, 0x16c, 0xd4520, 0xc0564, 
      0xde080, 0xdd7d8), at 0x5de88 
        [13] Tcl_EvalObjEx(0x0, 0xdd7d8, 0x20000, 0xc0564, 0x0, 
      0xd4520), at 0x33934 
        [14] Tcl_RecordAndEvalObj(0x0, 0xdd7d8, 0x20000, 
      0x20000, 0xd4520, 0x9), at 0x6d894 
        [15] Tcl_Main(0xc3554, 0xdcc80, 0xe7320, 0xc0564, 0x0, 
      0xd4520), at 0x1c110 
        [16] main(0x1, 0xffbeeb54, 0xffbeeb5c, 0xc3400, 0x0, 0x0), 
      at 0x1bac0 
      
      The UNIX specific function PipeCloseProc() contains this:
      
      
          if (pipePtr->isNonBlocking || TclInExit()) {
          
         /*
               * If the channel is non-blocking or Tcl is being cleaned 
      up, just
               * detach the children PIDs, reap them (important if we 
      are in a
               * dynamic load module), and discard the errorFile.
               */
              
              Tcl_DetachPids(pipePtr->numPids, pipePtr->pidPtr);
              Tcl_ReapDetachedProcs();
      
      
      There is no corresponding logic in the Windows specific 
      equivalent function
      PipeClose2Proc(). Should there be?
      
      
      
    2. login: "stevebold"
    3. mimetype: "text/plain"
    4. username: "stevebold"
  4. Ticket change [7805c9103c] (rid 89880) by davygrvy on 2004-06-03 02:12:57:

    1. assignee changed to: "davygrvy"
    2. icomment:
      Logged In: YES 
      user_id=7549
      
      Could be, yes.  If we do, we won't get an exitcode.  It's 
      arguable that the windows pipe driver isn't doing this 
      correctly.  It's been brought up before on c.l.t.
      
      I'll look into it.
      
      
    3. login: "davygrvy"
    4. mimetype: "text/plain"
    5. username: "davygrvy"
  5. Ticket change [0059e68903] (rid 119305) by davygrvy on 2004-06-03 02:49:09:

    1. icomment:
      Logged In: YES 
      user_id=7549
      
      Attached is a patch that allows non-blocking close behavior, 
      but as you'll see the child process is not closed or even 
      zombied.
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  6. Add attachment "patch.txt" [639b8f587f] (rid 92608) by davygrvy on 2004-06-03 02:49:10.

  7. Ticket change [4e17ff98e0] (rid 127166) by davygrvy on 2004-06-03 02:49:10:

    1. icomment:
      
      
      File Added - 89327: patch.txt
      
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  8. Ticket change [174df38284] (rid 122465) by davygrvy on 2004-06-03 04:35:53:

    1. title changed to: "Close a non-blocking pipe can block on Win"
  9. Ticket change [5f8aa3bfe5] (rid 115833) by davygrvy on 2004-06-03 04:42:21:

    1. title changed to: "Closing a non-blocking pipe can block on Win"
  10. Ticket change [033f88e458] (rid 119794) by davygrvy on 2004-06-03 05:00:01:

    1. icomment:
      Logged In: YES 
      user_id=7549
      
      Here's a good test case:
      
      set p [open "|netstat 1" r]
      fconfigure $p -blocking 0
      read $p
      close $p
      
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  11. Ticket change [f1d79507f0] (rid 109428) by davygrvy on 2004-06-06 09:04:22:

    1. icomment:
      
      
      File Added - 89645: patch.txt
      
      Logged In: YES 
      user_id=7549
      
      New patch ready.  It includes a new [kill] command.  Docs nor 
      tests have been added yet.  They'll come next.
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  12. Add attachment "patch.txt" [d057dfa972] (rid 113161) by davygrvy on 2004-06-06 09:04:22.

  13. Ticket change [bed304bda8] (rid 102152) by davygrvy on 2004-06-06 09:06:38:

    1. icomment:
      Logged In: YES 
      user_id=7549
      
      new test case:
      
      set p [open "|netstat 1" r]
      fconfigure $p -blocking 0
      read $p
      kill $p            <- new to the core!
      close $p
      
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  14. Ticket change [21561dd56b] (rid 130566) by dkf on 2004-06-08 02:50:50:

    1. icomment:
      Logged In: YES 
      user_id=79902
      
      Reminder: a new core command with a public name requires a TIP.
      
      Interim Workaround: call it ::tcl::WinKill or something like
      that. :)
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  15. Ticket change [14a9c7289d] (rid 124433) by stevebold on 2004-06-11 23:13:35:

    1. icomment:
      Logged In: YES 
      user_id=810219
      
      The discussion of TIP 88 here:
      
      http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/tcl-
      core/1252059
      
      suggests that 'kill' is not likely to be accepted as the name
      for this and that settling on a name may be difficult. Would
      it be easier to separate a fix for the Windows behaviour of
      non-blocking close from the interface change to support
      process signalling/termination on Windows and UNIX?
      
      
      Also I'll record two relevant docs that I referenced on 
      comp.lang.tcl:
      
      http://support.microsoft.com/default.aspx?scid=kb;en-
      us;178893
      
      claims to offer a clean way to shutdown processes. However,
      it doesn't seem to work for processes launched from Tcl,
      where DETACHED_PROCESS is specified as a flag.
      
      http://www.microsoft.com/msj/0698/win320698.aspx
      
      Explains the helper process needed to make
      GenerateConsoleCtrlEvent() work and discusses a much nicer
      solution that is only available with Win 2000 and its
      successors.
      
      
      
    2. login: "stevebold"
    3. mimetype: "text/plain"
    4. username: "stevebold"
  16. Ticket change [3919861e20] (rid 112328) by dkf on 2004-06-15 16:15:54:

    1. icomment:
      Logged In: YES 
      user_id=79902
      
      I'd suggest that [::tcl::WinKill] or something like that
      would not cause too much trouble (private name in Tcl's
      private area); it's a global [kill] command that causes much
      more trouble.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  17. Ticket change [d4a5c78e3a] (rid 123487) by davygrvy on 2004-10-07 05:17:04:

    1. icomment:
      Logged In: YES 
      user_id=7549
      
      The child process should see that its stdin for EOF, thus
      signalling to it that it should close.  netstat.exe is one
      of many commandline windows apps that don't do the "normal"
      behavior.
      
      As adding [kill] sounds like a painful exercise in
      bureaucracy, I'll just add the dropping of an exitcode for
      non-blocking pipes to match the UNIX behavior.
      
      I expect that many existing scripts will have a problem with
      this, unfortunetly.
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  18. Ticket change [410475fb1b] (rid 116105) by davygrvy on 2004-11-09 11:12:39:

    1. icomment:
      Logged In: YES 
      user_id=7549
      
      patch committed to HEAD (r1.51 of tclWinPipe.c)
      
      Let's leave this open for a bit to see if any new issues
      arise because of this change.
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. resolution changed to: "Fixed"
    5. username: "davygrvy"
  19. Ticket change [f06a2ff3bf] (rid 109191) by davygrvy on 2004-11-24 04:26:12:

    1. closedate changed to: "2004-11-23T21:26:12"
    2. closer changed to: "davygrvy"
    3. icomment:
      Logged In: YES 
      user_id=7549
      
      ok, no reports of problems.. closing. :)
      
      
    4. login: "davygrvy"
    5. mimetype: "text/plain"
    6. status changed to: "Closed"
    7. username: "davygrvy"