TIP #355: STOP FAST RECYCLING OF CHANNEL NAMES ON UNIX ======================================================== Version: $Revision: 1.1 $ Author: Alexandre Ferrieux State: Draft Type: Project Tcl-Version: 8.7 Vote: Pending Created: Tuesday, 01 September 2009 URL: https://tip.tcl-lang.org355.html Post-History: ------------------------------------------------------------------------- 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][], 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 [] adds this stub entry, and updates all unix channel naming schemes to use it. COPYRIGHT =========== This document has been placed in the public domain. ------------------------------------------------------------------------- TIP AutoGenerator - written by Donal K. Fellows