Tcl Library Source Code

View Ticket
Login
2026-11-16
00:06 • Ticket [4811399edc] comm disconnect after race condition status still Open with 3 other changes artifact: 4447039aa4 user: serhiy.storchaka
00:06 • Ticket [1491894fff] comm "-listen 0" causes race conditions status still Open with 3 other changes artifact: 37049016dd user: serhiy.storchaka
2026-11-15
23:35
Fix [4811399edc], [1491894fff]: comm raised an error when a client disconnected after the "commIncoming race condition" warning. commLostConn now clears the pending sends and the peer entry only when the lost connection is the registered one, and the warning is no longer printed for remote id 0, which all non-listening clients share. leaf check-in: 09fc83dd5b user: serhiy.storchaka tags: comm-lost-conn-peer
2015-11-09
22:32 • New ticket [4811399edc] comm disconnect after race condition. artifact: 3071cf6882 user: anonymous

Ticket UUID: 4811399edce1b2ef306b93141169d921ef833f8d
Title: comm disconnect after race condition
Type: Bug Version: 4.6.3.1
Submitter: anonymous Created on: 2015-11-09 22:32:28
Subsystem: comm Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2026-11-16 00:06:15
Resolution: None Closed By: nobody
    Closed on:
Description:
When 2 incoming connections are received simultaneously, comm displays a race condition warning. If the connections are from the same process, an error is displayed when the process disconnects.

To replicate, run the following scripts in tclsh:

Server:

    package require comm
    ::comm::comm configure -port 5000
    vwait forever

Client:

    package require comm

    proc mysocket {host port} {
        set sock [socket -async $host $port]
        update
        return $sock
    }
    
    ::comm::comm config -socketcmd mysocket -listen 0
    
    after 0 [list ::comm::comm send {5000 localhost} pid]
    after 0 [list ::comm::comm send {5000 localhost} pid]
    
    after 1000 set forever 1
    vwait forever

This produces the following output on the server:

    commIncoming race condition: 0
    peers=sock0000000002CC4FB0 port=5000
    can't read "comm(::comm::comm,pending,0)": no such element in array
        while executing
    "foreach s $comm($chan,pending,$id) {
            if {[string equal "callback" [lindex $s end]]} {
                set ser [lindex $s 0]
                if {[info exists comm($chan,ret..."
        (procedure "commLostConn" line 14)
        invoked from within
    "commLostConn $chan $fid "target application died or connection lost""
        (procedure "::comm::commCollect" line 12)
        invoked from within
    "::comm::commCollect ::comm::comm sock0000000002CC4E30"

The warning message is distracting since the user can't prevent the condition, but the error message should definitely be removed.
User Comments: serhiy.storchaka added on 2026-11-16 00:06:15:

Proposed fix in branch comm-lost-conn-peer: commLostConn assumed one connection per remote id. Now only the connection registered as the peer clears the pending sends and the peer entry, and the race warning is no longer printed for remote id 0, which all non-listening clients share. Test comm-4811399edc. Also fixes [1491894fff].