Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2014-08-02
09:13 • Closed ticket [3059220fff]: On Windows non-blocking pipe does not flush plus... artifact: 59220a6fac user: apnadkarni
2010-09-04
15:24 • Ticket [3059220fff]: 4 changes artifact: 910a7d8dc9 user: ferrieux
05:18 • New ticket [3059220fff]. artifact: 1a50187ea0 user: apnadkarni

On Windows non-blocking pipe does not flush

Closed3059220fffffffffffffffffffffffffffffffffCreated 16 years agoUpdated 12 years ago
Descriptionplain2010-09-04 05:18:51
After writing consecutive newlines on a line buffered non-blocking channel pipe to a child process, the parent tclsh process seems to stop flushing further writes unless event loop is run. 

Windows XP, both 8.6 CVS head and 8.5.8
See sample session:

% set fd [open {| ./tclsh85.exe} r+]
file9cfd08
% fconfigure $fd -buffering line -blocking 0
% puts $fd {puts foo}   ;# Ask child process to echo foo
% gets $fd                 ; # Read back response
foo
% puts $fd {puts foo}  ; # Once more just to verify
% gets $fd
foo
% puts $fd {
}
% gets $fd   ; # Fine, non-blocking, empty string returned as child was not asked to send back a response
% puts $fd {puts foo}  ; # Now retry previous command
% gets $fd                ; # Unlike before, no response, expected "foo" as before
% flush $fd               ; # SHould not be necessary, but just in case
% gets $fd               ; # flush no use
% update                 ; # Run event loop
% gets $fd               ; Ah now channel gets flushed, and child returns response
foo

Not clear if above is a bug, or my understanding (that non-blocking I/O does not need the event loop if filevents are not being used) is incorrect. I don't see why the behaviour in echoing "foo" changes after writing the empty line
Tracing indicates the following:
- the data is not being flushed from the parent process output buffer
- exiting the parent before the update results in all pending data being flushed (as expected). The child then sees that data (not shown above, but verified through logging)
- Removing the -buffering line gets rid of the issue, at least for this particular sequence
- if instead of writing puts {
} you write puts "" on consecutive command lines, the problem does not show.

/Ashok
ferrieuxplain2010-09-04 15:24:11
Weird indeed :/
Not reproducible in Linux (too bad since we have strace).

Just one minor comment about "non-blocking I/O does not need the event loop if filevents are not being used":
The truth is that a nonblocking write that has been only partially done, because of a full pipe buffer for example, creates an internal "fileevent writable" to resubmit the rest when the channels unlocks. So this secondary IO needs the event loop. But in your example, the tiny strings you write to the child cannot be blamed for filling a pipe buffer (typically 4k)...  Hence you are right that all these writes should be done immediately and completely.

Random shots to probe the ugly internals of Windows IO:
 - try unbuffered
 - play with the crlf/binary translation
 - replace  [puts \n] with [puts -nonewline \n\n]
apnadkarniplain2014-08-02 09:13:16
Closed my bug because fconfigure documentation states clearly (at least in the current version) that the event loop is required for non-blocking i/o to flush.
Log in (anonymous is fine) to add a comment.