<i>Blocking [gets] on a [chan push] transformed channel waits for 4096 bytes or EOF</i>.
by
.
D 2026-10-17T10:51:11.710
J cmimetype text/x-fossil-wiki
J comment A\sblocking\s<nowiki>[gets]</nowiki>\s(or\s<nowiki>[read\s$ch\s$n]</nowiki>)\son\sa\schannel\swith\sa\sreflected\stransform\s(<nowiki>[chan\spush]</nowiki>)\sdoes\snot\sreturn\swhile\scomplete\slines\sare\savailable.\sIt\swaits\suntil\sthe\stransform\shas\sfilled\sthe\swhole\s4096-byte\sinput\sbuffer\sor\sthe\sother\sside\scloses\sthe\schannel.\sWithout\sthe\stransform\sthe\ssame\s<nowiki>[gets]</nowiki>\sreturns\sat\sonce.\n\nRepro\swith\sa\spipe\s(a\ssocket\sbehaves\sthe\ssame):\n\n<verbatim>\nproc\sxform\s{cmd\shandle\sargs}\s{\n\s\s\s\sswitch\s--\s$cmd\s{\n\s\s\s\s\s\s\s\sinitialize\s{return\s{initialize\sfinalize\sread\swrite}}\n\s\s\s\s\s\s\s\sfinalize\s{}\n\s\s\s\s\s\s\s\sread\s-\swrite\s{return\s[lindex\s$args\s0]}\n\s\s\s\s}\n}\n#\schild\swrites\sthree\slines\sand\skeeps\sits\sstdout\sopen\sfor\s3\sseconds\nset\sf\s[open\s[list\s|\s[info\snameofexecutable]\s<<\s{\n\s\s\s\sputs\s-nonewline\s"one\\ntwo\\nthree\\n";\sflush\sstdout;\safter\s3000\n}]\sr]\nchan\spush\s$f\sxform\nafter\s500\nset\st0\s[clock\smilliseconds]\nset\sline\s[gets\s$f]\nputs\s"gets\s->\s$line\safter\s[expr\s{[clock\smilliseconds]-$t0}]\sms"\n</verbatim>\n\nActual:\s<tt>gets\s->\sone\safter\s2500\sms</tt>\s(returns\sonly\swhen\sthe\schild\sexits).\n\nExpected:\s<tt>gets\s->\sone\safter\s0\sms</tt>,\sas\swithout\sthe\s<nowiki>[chan\spush]</nowiki>.\n\nCause:\s<tt>ReflectInput()</tt>\sin\sgeneric/tclIORTrans.c\sloops\s"until\sthe\srequest\sis\ssatisfied"\sand\scalls\s<tt>Tcl_ReadRaw()</tt>\son\sthe\sparent\schannel\sagain\safter\sit\salready\shas\sdata.\sIn\sblocking\smode\sthat\ssecond\sread\sblocks.\sOnly\sthe\snon-blocking\scase\sreturns\sa\sshort\sread\s(when\s<tt>Tcl_InputBlocked()</tt>\sreports\sit).\sA\splain\schannel\sdriver\sreturns\swhat\sone\sread\sgives,\sso\s<tt>ReflectInput()</tt>\scould\sstop\sreading\sfrom\sthe\sparent\sonce\sit\shas\ssome\sdata.\n\nThe\sloop\sdates\sfrom\sthe\sTIP\s#230\simplementation\s[057ba9eab5].\sReproduced\swith\s8.6.0\sthrough\s8.6.18,\s9.0.5\sand\smain\s(Linux,\spipes\sand\ssockets).
J foundin 8.6.18,\s9.0.5,\s9.1.0
J login serhiy.storchaka
J priority 5\sMedium
J resolution None
J severity Important
J status Open
J subsystem 26.\sChannel\sTransforms
J title Blocking\s[gets]\son\sa\s[chan\spush]\stransformed\schannel\swaits\sfor\s4096\sbytes\sor\sEOF
J type Bug
K d48728e10b820296e45fa73202e135f90952cb46
U serhiy.storchaka
Z 4ce89cbc4c17a19f91beaf8a628055f6