Artifacts Associated With Ticket d48728
Ticket change [230bd19372] (rid 258525) by serhiy.storchaka on 2026-10-17 10:51:11:
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
A blocking <nowiki>[gets]</nowiki> (or <nowiki>[read $ch $n]</nowiki>) on a channel with a reflected transform (<nowiki>[chan push]</nowiki>) does not return while complete lines are available. It waits until the transform has filled the whole 4096-byte input buffer or the other side closes the channel. Without the transform the same <nowiki>[gets]</nowiki> returns at once. Repro with a pipe (a socket behaves the same): <verbatim> proc xform {cmd handle args} { switch -- $cmd { initialize {return {initialize finalize read write}} finalize {} read - write {return [lindex $args 0]} } } # child writes three lines and keeps its stdout open for 3 seconds set f [open [list | [info nameofexecutable] << { puts -nonewline "one\ntwo\nthree\n"; flush stdout; after 3000 }] r] chan push $f xform after 500 set t0 [clock milliseconds] set line [gets $f] puts "gets -> $line after [expr {[clock milliseconds]-$t0}] ms" </verbatim> Actual: <tt>gets -> one after 2500 ms</tt> (returns only when the child exits). Expected: <tt>gets -> one after 0 ms</tt>, as without the <nowiki>[chan push]</nowiki>. Cause: <tt>ReflectInput()</tt> in generic/tclIORTrans.c loops "until the request is satisfied" and calls <tt>Tcl_ReadRaw()</tt> on the parent channel again after it already has data. In blocking mode that second read blocks. Only the non-blocking case returns a short read (when <tt>Tcl_InputBlocked()</tt> reports it). A plain channel driver returns what one read gives, so <tt>ReflectInput()</tt> could stop reading from the parent once it has some data. The loop dates from the TIP #230 implementation [057ba9eab5]. Reproduced with 8.6.0 through 8.6.18, 9.0.5 and main (Linux, pipes and sockets). - foundin initialized to: "8.6.18, 9.0.5, 9.1.0"
- login: "serhiy.storchaka"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- subsystem initialized to: "26. Channel Transforms"
- title initialized to:
Blocking [gets] on a [chan push] transformed channel waits for 4096 bytes or EOF
- type initialized to: "Bug"
Ticket change [ef8f35ffa6] (rid 258554) by serhiy.storchaka on 2026-10-17 11:39:03:
- icomment:
Proposed fix in branch [/timeline?r=transform-short-read|transform-short-read]: <tt>ReflectInput()</tt> returns a short read once it has data, as other channel drivers do; <nowiki>[gets]</nowiki> and <nowiki>[read]</nowiki> ask again if they need more. Test iortrans-bug-d48728e10b.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [9cf90d6a28] (rid 259530) by serhiy.storchaka on 2026-10-20 18:11:28:
- submitter changed to: "serhiy.storchaka"
Ticket change [e4218c487a] (rid 262032) by jan.nijtmans on 2026-11-22 22:59:10:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2461367.4577562385"
- closer changed to: "jan.nijtmans"
- comment changed to:
A blocking <nowiki>[gets]</nowiki> (or <nowiki>[read $ch $n]</nowiki>) on a channel with a reflected transform (<nowiki>[chan push]</nowiki>) does not return while complete lines are available. It waits until the transform has filled the whole 4096-byte input buffer or the other side closes the channel. Without the transform the same <nowiki>[gets]</nowiki> returns at once. Repro with a pipe (a socket behaves the same): <verbatim> proc xform {cmd handle args} { switch -- $cmd { initialize {return {initialize finalize read write}} finalize {} read - write {return [lindex $args 0]} } } # child writes three lines and keeps its stdout open for 3 seconds set f [open [list | [info nameofexecutable] << { puts -nonewline "one\ntwo\nthree\n"; flush stdout; after 3000 }] r] chan push $f xform after 500 set t0 [clock milliseconds] set line [gets $f] puts "gets -> $line after [expr {[clock milliseconds]-$t0}] ms" </verbatim> Actual: <tt>gets -> one after 2500 ms</tt> (returns only when the child exits). Expected: <tt>gets -> one after 0 ms</tt>, as without the <nowiki>[chan push]</nowiki>. Cause: <tt>ReflectInput()</tt> in generic/tclIORTrans.c loops "until the request is satisfied" and calls <tt>Tcl_ReadRaw()</tt> on the parent channel again after it already has data. In blocking mode that second read blocks. Only the non-blocking case returns a short read (when <tt>Tcl_InputBlocked()</tt> reports it). A plain channel driver returns what one read gives, so <tt>ReflectInput()</tt> could stop reading from the parent once it has some data. The loop dates from the TIP #230 implementation [057ba9eab5]. Reproduced with 8.6.0 through 8.6.18, 9.0.5 and main (Linux, pipes and sockets). - icomment:
Merged to [0d03b1f576|trunk], core-9-0-branch and core-8-6-branch Many thanks!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"