TIP 361: Releasing Channel Buffers

Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2017 Conference, Houston/TX, US, Oct 16-20
Send your abstracts to tclconference@googlegroups.com
by Aug 21.
Author:		Wayne Cuddy <wcuddy@useunix.net>
State:		Draft
Type:		Project
Vote:		Pending
Created:	03-Feb-2010
Tcl-Version:	8.7


Tcl should provide a mechanism by which a channel's output buffer can be released without requiring that Tcl flush any remaining data in the buffer to the operating system. This is of particular interest with output mechanisms which can block indefinitely causing the interpreter to consume unnecessary resources or prevent the interpreter from exiting.


When working with processes that handle multiplexing/non-blocking I/O it is not uncommon to write, or call puts, with more data than the operating system will accept. Thus Tcl begins to buffer this data using internal buffers at the application level and flushes the data in the background. Problems arise when the consumer of this data, be it the other end of a socket, pipe or FIFO, refuse to read data and do not close the channel.

This has adverse effects on the close function and consequently the interpreter/process when it attempts to flush and close channels during finalization.


  1. When close is issued on a non-blocking channel Tcl removes the channel from pool of accessible channels from the current interpreter and attempts to flush any remaining data in the output buffers before closing the channel. Since the other end of the channel is not consuming data Tcl will never be able to flush it's internal buffers nor close the lower level channel driver. In a multiplexing server which opens new channels this will eventually result in resource starvation or denial of service.

  2. When exit is called Tcl attempts to flush all output buffers, if any open channel blocks the interpreter will be unable exit and must be forcibly terminated by OS specific mechanisms.

Propose API Additions

Provide a function and/or flags to existing functions which can be used to clear internal buffers without flushing.


This document has been placed in the public domain.