: <i>Blocking [gets] on a [chan push] transformed channel waits for 4096 bytes or EOF</i> plus 8 other changes
by
.
D 2026-11-22T22:59:10.139
J assignee jan.nijtmans
J closedate 2461367.4577562385
J closer jan.nijtmans
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.\r\n\r\nRepro\swith\sa\spipe\s(a\ssocket\sbehaves\sthe\ssame):\r\n\r\n<verbatim>\r\nproc\sxform\s{cmd\shandle\sargs}\s{\r\n\s\s\s\sswitch\s--\s$cmd\s{\r\n\s\s\s\s\s\s\s\sinitialize\s{return\s{initialize\sfinalize\sread\swrite}}\r\n\s\s\s\s\s\s\s\sfinalize\s{}\r\n\s\s\s\s\s\s\s\sread\s-\swrite\s{return\s[lindex\s$args\s0]}\r\n\s\s\s\s}\r\n}\r\n#\schild\swrites\sthree\slines\sand\skeeps\sits\sstdout\sopen\sfor\s3\sseconds\r\nset\sf\s[open\s[list\s|\s[info\snameofexecutable]\s<<\s{\r\n\s\s\s\sputs\s-nonewline\s"one\\ntwo\\nthree\\n";\sflush\sstdout;\safter\s3000\r\n}]\sr]\r\nchan\spush\s$f\sxform\r\nafter\s500\r\nset\st0\s[clock\smilliseconds]\r\nset\sline\s[gets\s$f]\r\nputs\s"gets\s->\s$line\safter\s[expr\s{[clock\smilliseconds]-$t0}]\sms"\r\n</verbatim>\r\n\r\nActual:\s<tt>gets\s->\sone\safter\s2500\sms</tt>\s(returns\sonly\swhen\sthe\schild\sexits).\r\n\r\nExpected:\s<tt>gets\s->\sone\safter\s0\sms</tt>,\sas\swithout\sthe\s<nowiki>[chan\spush]</nowiki>.\r\n\r\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.\r\n\r\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 icomment Merged\sto\s[0d03b1f576|trunk],\score-9-0-branch\sand\score-8-6-branch\r\n\r\nMany\sthanks!
J login jan.nijtmans
J mimetype text/x-fossil-wiki
J resolution Fixed
J status Closed
K d48728e10b820296e45fa73202e135f90952cb46
U jan.nijtmans
Z fa65e663636069441b681a0587a2bbbe