Skip to content
Tcl Source Code History Of Ticket d48728
Login

History Of Ticket d48728

Artifacts Associated With Ticket d48728

  1. Ticket change [230bd19372] (rid 258525) by serhiy.storchaka on 2026-10-17 10:51:11:

    1. cmimetype initialized to: "text/x-fossil-wiki"
    2. 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).
      
    3. foundin initialized to: "8.6.18, 9.0.5, 9.1.0"
    4. login: "serhiy.storchaka"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. severity initialized to: "Important"
    8. status initialized to: "Open"
    9. subsystem initialized to: "26. Channel Transforms"
    10. title initialized to:
      Blocking [gets] on a [chan push] transformed channel waits for 4096 bytes or EOF
      
    11. type initialized to: "Bug"
  2. Ticket change [ef8f35ffa6] (rid 258554) by serhiy.storchaka on 2026-10-17 11:39:03:

    1. 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.
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"
  3. Ticket change [9cf90d6a28] (rid 259530) by serhiy.storchaka on 2026-10-20 18:11:28:

    1. submitter changed to: "serhiy.storchaka"
  4. Ticket change [e4218c487a] (rid 262032) by jan.nijtmans on 2026-11-22 22:59:10:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2461367.4577562385"
    3. closer changed to: "jan.nijtmans"
    4. 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).
      
    5. icomment:
      Merged to [0d03b1f576|trunk], core-9-0-branch and core-8-6-branch
      
      Many thanks!
      
    6. login: "jan.nijtmans"
    7. mimetype: "text/x-fossil-wiki"
    8. resolution changed to: "Fixed"
    9. status changed to: "Closed"