# TIP 355: Stop Fast Recycling of Channel Names on Unix
Author: Alexandre Ferrieux <[email protected]>
State: Draft
Type: Project
Vote: Pending
Created: 01-Sep-2009
Tcl-Version: 9.1
Post-History:
Tcl-Ticket: 2826430
-----
# Abstract
This TIP proposes to put an end to the unix-specific habit of naming channels
after the underlying file descriptor, by using a much longer-lived incremented
counter instead.
# Background
Tcl \(non-reflected\) channel names are of the general form $_KIND_$_HANDLE_
on all OSes, $_KIND_ being something like "**file**", "**pipe**", etc,
and $_HANDLE_ being the OS file descriptor or handle. This is clearly a
cost-effective way of guaranteeing process-wide unicity at any given time.
However, on unix, file descriptors are in a "compact table", i.e. they are
small integers that are reused as quickly as possible, to keep the range small
for efficiency reasons \(and also constraints like the select\(\) API\). And as
witnessed by [Bug
2826430]<https://sourceforge.net/support/tracker.php?aid=2826430> , channel
name recycling is dangerous. Quite possibly a bunch of applications running
today get occasionally hit, with very hard to decipher symptoms, and an even
harder to reproduce setup.
# Proposed Change
This TIP proposes to replace the file descriptor in unix channel names by an
ever-increasing, process-unique counter.
# Rationale
This change would bring unix channels in line with the rest of the crowd,
since Windows handles seem to have a very long cycle, and reflected channels
already use a counter. It could even be more ambitious in that \(1\) even
Windows channels use the counter instead of relying on the OS's lifetime
guarantee, and \(2\) reflected channels use the same counter instead of their
own. Choice left open for discussion.
The implementation is trivial: a new public function,
**Tcl\_GetProcessUniqueNum**, returns a global integer counter which is
incremented under mutex. \(It will wrap at MAXINT and I am listening to
whoever thinks it is still a problem...\).
# Reference Implementation
The patch attached to the aforementioned bug
<https://sourceforge.net/support/tracker.php?aid=2826430> adds this stub
entry, and updates all unix channel naming schemes to use it.
# Copyright
This document has been placed in the public domain.