Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: ae6cd57e67131fd64a418da5db3d655d8d402e1d
Ticket: 1958930fffffffffffffffffffffffffffffffff
exec with pipes and fileevents leaks ~2Mb everytime
User & Date: mgammon on 2008-05-06 17:45:08
Changes

  1. assignee changed to: "andreas_kupries"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    I'm running Tcl8.3.5 on Windows XP/SP2 & VC8.
    
    I think I've seen this reported as a bug before, many years back, but looking at the latest 8.5.2 tclWinPipe.c code it looks like its still there.
    
    I need to spawn the same child process 100s of times.
    After each child process dies a few seconds pass and then it is spawned again. When I do this I see the Virtual Size of the tcl interpreter process slowly growing each time by about 8Mb. With the 2Gb limit for 32bit execs this allows me to make about 250 launches before everything stops.
    
    I've cut it down to a simple tcl script that demonstrates a 2Mb leak each time. It would be 4Mb if I attach a pipe to the stderr channel too.
    
    ...................................................
    proc callback {chan fid} {
       read $fid
    }
    
    pipe in_r  in_w
    pipe out_r out_w
    
    fconfigure $out_r -blocking 0 -buffering none
    
    set pid [exec ls <@$in_r >@$out_w &]
    
    fileevent $out_r readable "callback stdout $out_r"
    
    # wait for "ls" to die
    sleep 1
    # MUST force the event loop to be processed
    update
    
    close $in_r
    close $in_w
    close $out_r
    close $out_w
    ...................................................
    
    run the above script repeatedly in the same interpreter session and watch the Virtual Size grow in ProcessExplorer.
    
    I've dug down into the code in tclWinPipe.c and I'm pretty sure its happening because of the TerminateThread calls used to kill the pipe read thread. 
    
    It has to resort to a TerminateThread because the ReadFile call in the read thread is blocked. What I don't quite understand is why it stays blocked even after the child process it is reading from is long dead.
    
    I've seen suggestions elsewhere that to get round the blocking problem of ReadFile it should be used in asynchronous mode.
    
    This bug is really crippling my app. I'd really like to see a fix for it soon.
    
    
    
    
    
    
  4. foundin changed to: "final: 8.3.5"
  5. is_private changed to: "0"
  6. priority changed to: "5 Medium"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "mgammon"
  10. subsystem changed to: "24. Channel Commands"
  11. title changed to:
    exec with pipes and fileevents leaks ~2Mb everytime
    
  12. type changed to: "Bug"