Skip to content

fix: detach ithreads and close client socket for Windows#21

Closed
toddr-bot wants to merge 3 commits intomainfrom
koan.toddr.bot/fix-issue-19
Closed

fix: detach ithreads and close client socket for Windows#21
toddr-bot wants to merge 3 commits intomainfrom
koan.toddr.bot/fix-issue-19

Conversation

@toddr-bot
Copy link

@toddr-bot toddr-bot commented Mar 21, 2026

Summary

Fixes the t/ithreadm.t test failure on Windows by addressing two issues in the ithreads server code path:

  1. Thread detachment: ChildFunc created threads but never called detach(), so the thread object was immediately discarded. On Windows, this undefined cleanup behavior can terminate the process after the second client connects.

  2. Client socket cleanup: After spawning a child thread, the parent's copy of the accepted client socket was only closed explicitly in fork mode. In ithreads mode it lingered until GC, which on Windows can cause handle conflicts with the child thread's dup'd copy. Now ithreads mode also calls ServClose after spawning, matching fork mode.

With these fixes, the Windows skip in t/ithreadm.t is removed.

Fixes #19

Changes

  • Explicitly detach() threads created in ChildFunc (ithreads mode)
  • Close client socket in parent after spawning ithreads child (same as fork mode)
  • Remove Windows skip from t/ithreadm.t

Test plan

  • Full test suite passes on Linux (ithreads tests skip on non-ithreads perls, as expected)
  • The fix needs verification on a Windows Perl with ithreads (e.g. Strawberry Perl) — CPAN Testers will validate this

Generated by Kōan /fix


Quality Report

Changes: 2 files changed, 3 insertions(+), 7 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

…ead test

The ithreadm.t test was disabled on Windows because the server process
would terminate after the second client thread connected. Two issues in
the ithreads code path contributed to this:

1. ChildFunc created threads but never detached them. The thread object
   was immediately discarded, causing undefined cleanup behavior when it
   went out of scope — on Windows this can terminate the process.

2. In the Bind accept loop, the parent's copy of the client socket was
   only closed explicitly in fork mode. In ithreads mode, the parent
   held the socket until GC, which on Windows can cause handle conflicts
   with the child thread's dup'd copy. Now ithreads mode also calls
   ServClose on the client socket after spawning the child thread, matching
   fork mode behavior.

Fixes #19

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@toddr-bot toddr-bot force-pushed the koan.toddr.bot/fix-issue-19 branch from d2d1740 to f17445e Compare March 21, 2026 23:11
@toddr-bot
Copy link
Author

Rebase: fix: detach ithreads and close client socket for Windows

Branch koan.toddr.bot/fix-issue-19 rebased onto main and force-pushed.

Diff: 2 files changed, 3 insertions(+), 7 deletions(-)

Actions

  • Rebased koan.toddr.bot/fix-issue-19 onto origin/main
  • Force-pushed koan.toddr.bot/fix-issue-19 to origin
  • CI failed (attempt 1)
  • Applied CI fix (attempt 1)
  • Pushed CI fix (attempt 1)
  • CI failed (attempt 2)
  • Applied CI fix (attempt 2)
  • Pushed CI fix (attempt 2)
  • CI still failing after 2 fix attempts

CI

CI still failing after 2 fix attempts.

Last failure logs
windows	Run Tests	2026-03-21T23:37:45.0473807Z ##[group]Run make test
windows	Run Tests	2026-03-21T23:37:45.0474255Z �[36;1mmake test�[0m
windows	Run Tests	2026-03-21T23:37:45.0547143Z shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
windows	Run Tests	2026-03-21T23:37:45.0547483Z ##[endgroup]
windows	Run Tests	2026-03-21T23:37:45.4123047Z "C:\strawberry\perl\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib\lib', 'blib\arch')" t/*.t
windows	Run Tests	2026-03-21T23:37:49.0000424Z t/base.t ........ ok
windows	Run Tests	2026-03-21T23:37:59.3345975Z t/config.t ...... ok
windows	Run Tests	2026-03-21T23:37:59.4421562Z t/fork.t ........ skipped: This test requires a system with working forks.
windows	Run Tests	2026-03-21T23:37:59.5520115Z t/forkm.t ....... skipped: This test requires a system with working forks.
windows	Run Tests	2026-03-21T23:38:01.7045877Z t/ithread.t ..... ok
windows	Run Tests	2026-03-21T23:38:04.1163635Z Child 5: Error while reading: 1 (Invalid argument) at t/ithreadm.t line 47.
windows	Run Tests	2026-03-21T23:38:04.1165314Z Child 3: Error while reading: 1 (Invalid argument) at t/ithreadm.t line 47, <GEN1> line 744.
windows	Run Tests	2026-03-21T23:38:04.1166416Z Child 4: Error while reading: 1 (Invalid argument) at t/ithreadm.t line 47, <GEN1> line 468.
windows	Run Tests	2026-03-21T23:38:04.6633670Z t/ithreadm.t .... 
windows	Run Tests	2026-03-21T23:38:04.6634085Z Dubious, test returned 116 (wstat 29696, 0x7400)
windows	Run Tests	2026-03-21T23:38:04.6634359Z Failed 9/10 subtests 
windows	Run Tests	2026-03-21T23:38:24.8555563Z t/loop-child.t .. ok
windows	Run Tests	2026-03-21T23:38:26.9868945Z t/loop.t ........ ok
windows	Run Tests	2026-03-21T23:38:29.1280053Z t/single.t ...... ok
windows	Run Tests	2026-03-21T23:38:29.2364918Z t/unix.t ........ skipped: (no reason given)
windows	Run Tests	2026-03-21T23:38:29.2366888Z 
windows	Run Tests	2026-03-21T23:38:29.2367212Z Test 

Automated by Kōan

@toddr toddr closed this Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

t/ithreadm.t is failing on windows.

2 participants