Skip to content
Tcl Source Code History Of Ticket 72d1c8c271
Login

History Of Ticket 72d1c8c271

Artifacts Associated With Ticket 72d1c8c271

  1. Ticket change [c1d7527219] (rid 260077) by serhiy.storchaka on 2026-10-23 07:07:25:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. comment initialized to:
      On Windows, when the ephemeral TCP ports are exhausted, Tcl 8.6 disables sockets for the whole process instead of reporting the error, and sometimes crashes.
      
      Reproduced on Windows 11 with the 8.6 tip (8.6.18, Thread 2.8.13). Each thread opens a server socket on a free port of 127.0.0.1 and a client connection to it, then exits with both open:
      
      <verbatim>
      package require Thread
      set script {
          set srv [socket -server {apply {{c a p} {set ::c $c}}} -myaddr 127.0.0.1 0]
          set cli [socket 127.0.0.1 [lindex [fconfigure $srv -sockname] 2]]
          update
      }
      for {set i 0} {$i < 1000} {incr i} {
          thread::join [thread::create -joinable $script]
      }
      </verbatim>
      
      Running it repeatedly fills the dynamic port range with TIME_WAIT connections (about 16300 of 16384). Then the first error is <tt>couldn't open socket: address already in use</tt>, as expected. But 8.6 then fails with <tt>sockets are not available on this system</tt> or <tt>winsock is not initialized</tt>, in every thread including the main one, for the rest of the process. In 5 of 40 runs of a stress script the process failed this way, 2 of them with a crash (SIGSEGV). Without port exhaustion it runs clean.
      
      9.0 and 9.1 in the same state just report <tt>address already in use</tt> (40 of 40 runs without failure each).
      
      Possible cause: <tt>InitSockets()</tt> in win/tclWinSock.c of 8.6 sets the global <tt>initialized</tt> to -1 when the per-thread setup fails in one thread, which disables sockets in all threads. 8.7 and 9.0 reworked this initialization. Backporting [a36f76eb6b] (for [40b1814b93]) to 8.6 did not help (4 of 40 runs still failed, 2 crashes). The crash may be related to [06f19cc401], fixed only on main.
      
    5. foundin initialized to: "8.6.18"
    6. is_private initialized to: "0"
    7. login: "serhiy.storchaka"
    8. priority initialized to: "5 Medium"
    9. resolution initialized to: "None"
    10. severity initialized to: "Important"
    11. status initialized to: "Open"
    12. submitter initialized to: "serhiy.storchaka"
    13. subsystem initialized to: "27. Channel Types"
    14. title initialized to:
      Windows 8.6: under ephemeral port exhaustion, sockets get disabled for the whole process and Tcl sometimes crashes
      
    15. type initialized to: "Bug"