<i>exec with pipes and fileevents leaks ~2Mb everytime</i> status still Open with 4 other changes
by
.
D 2008-05-07T14:14:25
J icomment Logged\sIn:\sYES\s\nuser_id=2080734\nOriginator:\sYES\n\nDavid,\smy\scallback\swasn't\stesting\sfor\sEOF\sas\sa\ssign\sof\sthe\schild's\sdeath\sand\sclosing\sthe\spipe\sthen.\sWhen\sI\sadd\sthat\sand\schange\sto\sa\svwait\son\sthe\sdeath\sthen\sthe\sscript\shangs.\sThe\scallback\sread\schars\sfrom\sthe\schild\sbut\snever\ssees\sa\sEOF.\sFrom\sthe\sdebugger\sit\slooks\slike\sthe\sTcl\sevent\sloop\sis\sspinning\sround\sand\schecking\sfor\sevents\son\sthe\spipes,\sthe\spipe\ssays\sits\sreadable\sbut\sthe\sread\sthread\sis\shung\sin\sa\scall\sto\sReadFile.\n\nI\sfound\sthis\sarticle\sfrom\sMS\sabout\show\sto\sdo\sthis\schild\sspawning\swith\spipes\sin\sC++:\n\n\s\s\shttp://support.microsoft.com/kb/190351\n\nLooking\sat\sthis\sI\sthink\sit\sexplains\swhy\sReadFile\sis\shanging.\sIt\ssays\sthe\sparent\sprocess\sMUST\sclose\sthe\sunused\schild\sends\sof\sthe\spipes\safter\sit\shas\sspawned\sthe\schild.\sIf\snot\sthen\sthe\schild\scan't\sclose\sthe\spipe\sproperly\swhen\sit\sdies,\sand\shence\sthe\spipe\sstays\sup\sand\sReadFile\sgets\shung\son\sit.\sI\sadded\sthis\sto\smy\sscript\sand\sbingo!,\sit\sall\sworks\sperfectly\snow.\sHere's\sthe\scurrent\sversion\sof\smy\sscript:\n\n...........................................................\nproc\scallback\s{out_r}\s{\n\s\s\sglobal\sisdead\n\s\s\secho\s"read\s[string\slength\s[read\s$out_r]]\schars"\s;\sflush\sstdout\n\s\s\s#\sMUST\stest\sfor\sEOF\scondition\sand\sclose\spipe\sNOW\n\s\s\sif\s{[eof\s$out_r]}\s{\n\s\s\s\s\s\secho\s"child\shas\sdied!"\s;\sflush\sstdout\n\s\s\s\s\s\sclose\s$out_r\n\s\s\s\s\s\sset\sisdead\s1\n\s\s\s}\n}\n\npipe\sin_r\sin_w\npipe\sout_r\sout_w\n\nfconfigure\s$out_r\s-blocking\s0\s-buffering\snone\n\nset\spid\s[exec\sls\s<@$in_r\s>@$out_w\s&]\n\n#\sMUST\sclose\sunused\schannels\sto\schild\selse\schild\scan't\sclose\spipe\swhen\sit\sdies\scausing\sread\sto\shang\nclose\s$in_r\nclose\s$out_w\n\nfileevent\s$out_r\sreadable\s"callback\s$out_r"\n\n#\swait\sfor\s"ls"\sto\sdie\nvwait\sisdead\n\nclose\s$in_w\n\n...........................................................\n\nI've\sinstrumented\stclWinPipe\sto\stell\sme\show\sthe\spipe\sread/write\sthreads\sare\sstopped.\sPreviously\sis\swas\susing\sthe\sleaky\sTerminateThread\scall\son\sthe\schild\sreader\sthreads,\sbut\snow\sthe\sthreads\sare\sstopping\sproperly\sin\sresponse\sto\sthe\sevent\ssignal.\sGreat!\n\nThere\sis\sone\sthing\sin\sthe\sMS\sarticle\sthat\sI'm\snot\sdoing.\sFor\ssome\sreason\sit\sduplicates\sthe\schild\sread\sand\swrite\spipes\sand\scloses\sthe\soriginal\schannels\sit\sgot\sfrom\sCreatePipe.\sNot\ssure\swhy\sits\sdoing\sthis.\sI\stried\sreproducing\sthis\swith\sthe\sTclX\s"dup"\scommand\sand\safter\shacking\sit\sto\sallow\sme\sto\sduplicate\sa\spipe\s(odd\srestriction?)\sI\sgot\smy\sscript\sdoing\sexactly\sthe\ssame\sas\sthe\sMS\sC++\scode.\sHowever\sI\sfound\sthat\smy\sscript\sworked\sjust\sfine\sWITHOUT\sdoing\sthis\sextra\sduplication,\sso\sI've\sleft\sit\sout.\n\nAlexandre:\sthanks\sfor\syour\shelp.\sJust\sseen\syour\slast\scomment.\sLooks\slike\syou\sare\son\sto\sthe\ssame\ssolution,\si.e.\sclosing\sthe\sunused\spipes\safter\sthe\sexec.\sI\sthink\sI've\sconfirmed\sthat\sthis\sdoes\scure\sthe\sproblem.\sBTW,\swe\sare\susing\sTclX8.2.0.\s\n\nI\sdon't\sthink\sI'm\sout\sof\sthe\swoods\syet\sthough\sas\swhen\sI\sreplace\sthe\schild\sprocess\s"ls.exe"\swith\smy\sreal\schild\sprocess,\sthen\sI'm\sstill\sseeing\sthe\schild\sreader\sthreads\skilled\sby\sTerminateThread.\sMy\sreal\schild\sprocess\sdoes\smore\sthan\s"ls"\sin\sthat\sit\ssits\sand\sreads\sfrom\sstdin\sand\ssends\sresponses\sdown\sit's\sstdout\sand\sstderr.\sI'll\ssee\sif\sI\scan\spin\sdown\swhy\sthis\sisn't\sbehaving\sas\scleanly\sas\sthe\ssimple\s"ls"\sexample.\n\nThanks\sa\slot\sto\syou\sboth\sfor\syour\sexcellent\shelp!\n
J login mgammon
J mimetype text/plain
J username mgammon
K 1958930fffffffffffffffffffffffffffffffff
U mgammon
Z 83899c9e16423a386a765889252a3770