Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 69b334730614c8dde847c8b5c53f5c620e808a99
Ticket: 2826430fffffffffffffffffffffffffffffffff
Channel name recycling is dangerous
User & Date: ferrieux on 2009-07-24 15:08:08
Changes

  1. icomment:
    Hmmm, there are two separate issues here: (1) removing the carpet under a coro/thread feet and (2) too fast reuse.
    I fail to see how this would solve (1), but for (2) it is clear. Can you clarify on (1) ?
    
    Regarding (2), the "compact set" arises from Tcl's direct use of OS handles/fd, and on unix fds are a compact set. On Windows AFAIK handles are not reused (correct m if I'm wrong). So, an alternative way of solving this issue, without any intervention from the script writer, would be to insert an indirection in Tcl, with an intentionally compact set managed by Tcl, but extended with generation counts, so that no reuse occurs:
    
        typedef struct {
               HANDLE_OR_INT fd;
               int gencount;
        } UniqueHandle; 
    
       UniqueHandle  *compactArrayOfFds;
    
    The idea, then, is to have automatic channel names of the form
    
         sock3g1
    
    which can be looked up from string in two steps:
    
        3 is the index in compactArrayOfFds
        1 is the gencount for verification
    
    This way, even if slot 3 of the array is reused, it will have a gencount of at least 2, hence any stale reference to sock3g1 will generate an error instead of wreaking havoc by unwanted IO on another channel.
    
    Note that this works well with the Channel intrep too, assuming we add the gencount to the structure. Then the gencount verification is just an extra integer comparison.
    
    Reactions ?
    
    
  2. login: "ferrieux"
  3. mimetype: "text/plain"
  4. username: "ferrieux"