Tcl Source Code

View Ticket
Login
Ticket UUID: 699739
Title: app can overrun console buffer on Windows
Type: Bug Created on: 2003-03-08 00:42:15
Submitter: kennykb Assigned to: davygrvy
Subsystem: 27. Channel Types Severity:
Priority: 5 Medium Last modified: 2026-11-13 11:18:46
Status: Open Closed by: davygrvy
Resolution: None Closed on: 2007-11-15 17:16:51
Version: None
Description:
If an application configures a very large buffer on stdout, and then writes
a large amount of data to the console on Windows, the write fails with

error writing "stdout": not enough memory

A script that illustrates the problem is:

fconfigure stdout -buffering full -buffersize 262144
for { set i 0 } { $i <= 10000 } { incr i } {
    puts ----------------------------------------------------------------------
}

It's reasonable for the write to block, but this failure is bizarre.
User Comments:
davygrvy added on 2004-06-01 16:50:52:
Logged In: YES 
user_id=7549

Just put tcl in the debugger to look at this.

WriteFile itself is failing in ConsoleOutputProc().  I think the 
summary of this problem is that the other end can't accept a 
buffer this big and rather than soaking up some of it, it just 
barfs.

I don't know if there is an easy way to fix this.  Even if we 
knew the limit ahead of time (maybe GetConsoleBufferInfo 
could get us the answer?) we have no way for the driver to 
intercept a setting of the buffersize from the driver side.

davygrvy added on 2004-06-03 02:24:20:
Logged In: YES 
user_id=7549

It seems the upper limit -buffersize is 0x7FFF.  One over that 
and WriteFile fails with ENOMEM.

I can't think of a way to fix this aside from adding a way for 
drivers to intercept requests to change the buffersize.

davygrvy added on 2007-11-16 00:16:51:
Logged In: YES 
user_id=7549
Originator: NO

I don't believe a fix for this is possible given there are no hooks available to a channel driver to restrict the generic side's standard fconfigure settings.  I've come across this before.  Also in the Console channel driver changing -encoding to something other than unicode when running on NT causes big problems.

Could this become a new TIP?  a new hook such that generic layer setting requests are forwarded to the driver for validation before accepted?

dkf added on 2007-11-16 05:32:26:

data_type - 360894