Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 230bd193725c23b02fd77a387793209ec9a115b7891aa748365f8a46da98d27e
Ticket: d48728e10b820296e45fa73202e135f90952cb46
Blocking [gets] on a [chan push] transformed channel waits for 4096 bytes or EOF
User & Date: serhiy.storchaka on 2026-10-17 10:51:11
Changes

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