Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: c1d7527219b976325a54d3282528582412f40f5c47d0876522a780a4f1daf544
Ticket: 72d1c8c271771764d340ce7e75c142f63048a7ad
Windows 8.6: under ephemeral port exhaustion, sockets get disabled for the whole process and Tcl sometimes crashes
User & Date: serhiy.storchaka on 2026-10-23 07:07:25
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed 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 changed to: "8.6.18"
  6. is_private changed to: "0"
  7. login: "serhiy.storchaka"
  8. priority changed to: "5 Medium"
  9. resolution changed to: "None"
  10. severity changed to: "Important"
  11. status changed to: "Open"
  12. submitter changed to: "serhiy.storchaka"
  13. subsystem changed to: "27. Channel Types"
  14. title changed to:
    Windows 8.6: under ephemeral port exhaustion, sockets get disabled for the whole process and Tcl sometimes crashes
    
  15. type changed to: "Bug"