Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 0812aa6d210cf4dd91e4c1b2bd584ec6e8e08ed2904b4363366d38875021dde5
Ticket: de232b49f26da1c18e07513d4c7caa203cd27910
write-only nonblocking refchan and Tcl internal buffers
User & Date: pooryorick on 2024-03-29 21:51:53
Changes

  1. icomment:
    The refchan issue described here is far more serious than the failure of
    test socket-14.11.0, because in a situation like the one illustrated by
    that test, at least the script becomes aware that the channel is broken,
    and has the opportunity to respond somehow.  In contrast, any script
    that falls victim to the refchan issue described in this ticket, it has
    no recourse, and simply fails silently and irretrievably.
    
    There are many ways in which channel can become broken, and a socket
    failure to connect is for practical purposes not much different than any
    of those other failure modes.  In my opinion, "async" should mean async
    from start to finish, and the script itself can decide how to handle the
    various possible failures in an asynchronous way. 
    
    In the meantime there are ways to avoid the problem Ashok illustrated
    with twapi in [080f846fd5].  For one thing, the example is a little
    strange:
    
      <code><verbatim>
          set so [twapi::tls_socket -async www.example.com 443]
          fconfigure $so -blocking 0
      </verbatim></code>
    
    The socket is opened in asynchronous mode, but the for some reason it is
    still necessary to set the blocking mode of the resulting channel to 0.
    Why the redundancy?  I would guess that if the "-async" argument were
    removed, then twapi would wait for the connection to complete, and then
    the rest of the code would continue to function asynchronously:
    
      <code><verbatim>
          set so [twapi::tls_socket www.example.com 443]
          fconfigure $so -blocking 0
      </verbatim></code>
    
    The same is true for socket-14.11.0.  The documentation for the "-async"
    option to [socket] has long described the possibility:  "This means that
    the socket will be created immediately but may not yet be connected to
    the server, when the call to socket returns."
    
    So even just following the documentation will avoid the issue Ashok has
    raised.  I would not revert this fix.  There may well be a more
    satisfying fix, and if it is found, it can of course replace this one.
    
  2. login: "pooryorick"
  3. mimetype: "text/x-fossil-wiki"