Artifacts Associated With Ticket 06f19cc4
Ticket change [4ab75e09e6] (rid 248753) by dkf on 2025-11-25 14:32:35:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
In what appears to be a recurrence of [217794], I'm getting crashes in <tt>socket-*-12.3</tt> (both address families, commit [4724603ffb] on <tt>trunk</tt>) apparently due to inheritance of the socket, but only when the process exits with an event loop running. Here's a typical piece of output: <verbatim> ==== socket_inet-12.3 testing inheritance of accepted sockets FAILED ==== Contents of test case: # Launch the script2 process and connect to it. See how long the socket # stays open ## exec [interpreter] script2 & set p [open "|[list [interpreter] $path(script2)]" r] gets $p listen set f [socket $localhost $listen] fconfigure $f -buffering full -blocking 0 fileevent $f readable [list getdata $f] # If the socket is still open after 5 seconds, the script1 process must # have inherited the accepted socket. set failed 0 set after [after 5000 [list set x "accepted socket was inherited"]] proc getdata { file } { # Read handler on the client socket. global x global failed set status [catch {read $file} data] if {$status != 0} { set x "read failed, error was $data" } elseif {[string compare {} $data]} { } elseif {[fblocked $file]} { } elseif {[eof $file]} { set x "accepted socket was not inherited" } else { set x "impossible case" } return } vwait x set x ---- Test cleanup failed: child killed: segmentation violation ---- errorInfo(cleanup): child killed: segmentation violation while executing "close $p" ("uplevel" body line 5) invoked from within "uplevel 1 $cleanup" ---- errorCode(cleanup): CHILDKILLED 18364 SIGSEGV {segmentation violation} ==== socket_inet-12.3 FAILED </verbatim> The crash comes from one of the subprocesses launched, but <i>only when the innermost subprocess does an exit with the event loop still running;</i> altering the callbacks so that the subprocess exits after stopping the event loop (<tt>socket_*.12.4</tt>) prevents the crash. I don't think the code should crash. I don't know why the code is crashing. I've marked the test as a <tt>knownBug</tt>. - is_private initialized to: "0"
- login: "dkf"
- priority initialized to: "5 Medium"
- private_contact initialized to: "f6b536f9c1ed4b589e96e38fb613afc3d8991783"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "dkf"
- subsystem initialized to: "27. Channel Types"
- title initialized to: "socket_*-12.3 crashes on Windows 11"
- type initialized to: "Bug"
Ticket change [e068f43228] (rid 248754) by sebres on 2025-11-25 16:03:33:
- icomment:
I don't think changes of 12.4 "fixed" that. Because the exe of script1 running really 10 seconds (in both cases, by 12.3 or 12.4), where the test got "not inherited" already after few milliseconds (and test ends then). The helper-exe (supposed to check whether the socket handle may be shared across child processes) is running further and doesn't exit on done (because no eof - no readable event), but on <code>[after]</code>. What would be a nonsense for a segfault. Moreover "child killed" with segfault is from script2, not from script1 (where your changed it), because script1 is started as detached process by <code>[exec $tcltest $delay &]</code> and cannot throw it (especially because it still always running after the test end). Looks rather like a sporadic bug to me. I can also not reproduce it with 9.0/trunk, neither with test 12.3, nor with test 12.4, even if I run them in timerate hundred times. How good it is reproducible on your side, Donal? Or did you speak only about CI (GHA)?
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [59ff85b5c1] (rid 248805) by dkf on 2025-11-26 12:49:48:
- icomment:
I wouldn't have bothered reporting this unless it was reproducible on my end. The only change I needed to apply to get the behaviour to alter was in `script1` to make `after 10000 exit` (the timeout case) to become `after 10000 set forever 1` (i.e., to slay the event loop), which made the test not report a SEGV on cleanup. This shouldn't be occurring... but it looks like the server socket, or the client socket it makes on connect, (both in `script2`) are getting leaked into `script1` under circumstances that I don't understand. (This machine _is_ dual-homed IPv4 and IPv6 on this network; that might matter?) (I was _actually_ hunting for tests that fail because of wrong handling of spaces in directory names...)
- login: "dkf"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [b533f9b3eb] (rid 248806) by dkf on 2025-11-26 13:06:51:
- icomment:
OK, it's only _semi-reliably_ crashing. Yuck. Sounds like a race condition. The crashes appear to be originating from `script2`, or at least the PID reported in the `errorCode` correlates with the PID of the subprocess made directly there. I've also seen 12.2 crash, though only the one time.
- login: "dkf"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [3e5a4be9dd] (rid 248807) by sebres on 2025-11-26 13:31:34:
- icomment:
<blockquote>> The crashes appear to be originating from script2</blockquote> Exactly my point. As well as related to backtrace from the ticket it happened while executing "close $p" (which is definitely pipe of script2). I'm still unable to reproduce it, no matter what I do.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [0d9d506345] (rid 248808) by dkf on 2025-11-26 14:04:16:
- icomment:
I'm wondering if it's relating to how Windows Defender is configured to run on this machine (something I've _very_ little visibility of and even less control over).
- login: "dkf"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [ec290e092b] (rid 248810) by sebres on 2025-11-26 14:38:43:
- icomment:
Hmm... socket_*-12.1 is not correct (algorithmically) - it opens listener on some free port in child process and output the port to parent, but the parent never reads it and thus the test never tries to open that port, because instead it covers <code>[socket $localhost $listen]</code>. What uses completely wrong listener port here.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [09f46161c6] (rid 248811) by sebres on 2025-11-26 15:06:27:
- icomment:
Similar thing is with 12.2, however a bit different - it trying to cover that accepted socket is not inherited by child of child, but doesn't close it properly in child itself, so it seems to work only in a RC. Moreover after some of tests child processes left behind (and ends only by 10 seconds timeout), what can also confuse the next tests (as for inheritance check consistence). I'll try to fix all 12.* tests now (regarding their consistence and correctness, regardless the segfault in original tests).
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [deb67ca7dc] (rid 248813) by sebres on 2025-11-26 15:44:08:
- icomment:
[26240753b7a764f9] shall fix all found issues (what I mentioned before, however not SF). @dkf, since it is not about segfault, just a consistence/correctness fix, but since I'm unable to reproduce the SF in my boxes, can you possible try it on your side (whether it'd also avoid SF)? Just would be good to know to investigate deeper for original issue.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [a024b23d34] (rid 248828) by dkf on 2025-11-27 09:15:03:
- icomment:
Rerunning that part of the test suite while I write this, but focused testing looks good... I didn't want to just fix the tests though. I was more concerned that there was a crash in the first place.
- login: "dkf"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [0bf485f181] (rid 248830) by dkf on 2025-11-27 09:15:59:
- icomment: "Full run of `socket.test` passed."
- login: "dkf"
- mimetype: "text/x-markdown"
Ticket change [4f60f57700] (rid 248841) by sebres on 2025-11-27 13:36:51:
- icomment:
<blockquote>> I didn't want to just fix the tests though. I was more concerned that there was a crash in the first place.</blockquote> This was also my intention, just... I'd like to understand what exactly may cause the segfault by exit in child. However since the 2 from 3 tests were functional wrong, I thought it'd be better to repair them. The previous (segfaulting) version is in the repository too and even if I merge the new versions, the previous can be also created by revert/backout of merge or switch to some old revision (and tee in another branch). I guess it has probably nothing with socket, but with exit/finalization process or pipes.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [92d530f720] (rid 252089) by apnadkarni on 2026-03-14 02:53:41:
- icomment:
For the record, socket-12.4 also crashed with a segmentation violation that looks very similar in one of my github CI runs. Cannot reproduce despite running continuously in a loop and have never seen it before on my own systems.
- login: "apnadkarni"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [3c69129b01] (rid 252422) by apnadkarni on 2026-04-02 08:19:24:
- icomment:
For the record, 12.3 crash also appeared again on core-9-0-branch in Github CI, gcc --enable-symbols build.
- login: "apnadkarni"
- mimetype: "text/plain"
- icomment:
Ticket change [4e4557424a] (rid 253960) by apnadkarni on 2026-05-27 09:09:13:
- icomment:
Examining the github logs, it appears this has only shown up with memory debug enabled, (configure --enable-symbols=mem or nmake OPTS=symbols STATS=compdbg,memdbg) Will try to reproduce that locally.
- login: "apnadkarni"
- mimetype: "text/plain"
- icomment:
Ticket change [5cd291ebca] (rid 253961) by apnadkarni on 2026-05-27 09:09:27:
- login: "apnadkarni"
- mimetype: "text/plain"
- severity changed to: "Important"
Ticket change [8a06d02133] (rid 253990) by apnadkarni on 2026-05-28 06:40:09:
- icomment:
Managed to reliably reproduce by running the tests continuously. Fails within 30 iterations due to use after free. The bug is present in release builds as well but shows up more easily in debug builds because the C ucrt/msvcrt runtimes scrub memory only in debug builds. Proposed fix is in the bug-06f19cc4-with-tcltest branch. Diagnosis: The socket implementation of Windows maintains a separate "socket thread" for a Tcl thread to handle socket I/O. The list of live sockets is maintained in a TSD list within the Tcl thread and also shared with the socket thread. When a channel is in normal operation, the socket state structure is removed from this list via the socket channel implementation's ThreadActionProc (via a CutChannel call). However, when a thread exits, TclFinalizeIOSubsystem frees the socket state structure without calling CutChannel. The socket thread still has access to it via the shared list and depending on when the socket closure windows message is received, accesses the freed memory. The fix simply adds a CutChannel to TclFinalizeIOSubsystem prior to the ChanClose. I believe this should apply to all platforms but I'm not sure of the Unix implementations so it's ifdef'ed to WIN32. Although a one-liner, it's also a fairly low level change that needs substantial airtime for an issue that only arises on thread exits with open sockets so do not think it should be backported to 9.0.4. Reviews welcomed.
- login: "apnadkarni"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [f6e27a4c02] (rid 254131) by apnadkarni on 2026-05-29 15:08:05:
- closedate changed to: "2461190.1306196526"
- closer changed to: "apnadkarni"
- icomment: "Fixed in [361fb72eaa] for 9.1."
- login: "apnadkarni"
- mimetype: "text/x-fossil-plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [d2d7c64d13] (rid 262116) by jan.nijtmans on 2026-11-25 15:13:02:
- assignee changed to: "apnadkarni"
- closedate changed to: "2461370.1340545025"
- closer changed to: "jan.nijtmans"
- icomment:
Seen again in 8.6 build (e.g. [https://github.com/tcltk/tcl/actions/runs/45570869511/job/139223471171|here], therefore now backported to 9.0 and 8.6 too.
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"