Skip to content

fix: repair dead $RegExpLock and modernize Bind()#33

Draft
toddr-bot wants to merge 3 commits intomainfrom
koan.toddr.bot/fix-regexplock
Draft

fix: repair dead $RegExpLock and modernize Bind()#33
toddr-bot wants to merge 3 commits intomainfrom
koan.toddr.bot/fix-regexplock

Conversation

@toddr-bot
Copy link

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

What

Fix two long-standing bugs that made $RegExpLock completely non-functional in ithreads mode, plus modernize PID file handling in Bind().

Why

The $RegExpLock regex thread-safety mechanism has been dead code since the ithreads mode was introduced:

  1. threads::shared::share($RegExpLock) was gated by $forks::threads, which is always false when using real ithreads (the $use_ithreads guard on line 43 already excludes forks.pm). The variable was never actually shared between threads.

  2. The lock acquisition in Accept() and t/server checked $self->{'mode'} eq 'threads', but the mode value is 'ithreads' — the lock was never acquired.

On modern Perl (5.10+ required for ithreads in this code), regex is thread-safe, so the lock is defensive rather than critical. But any subclass relying on $RegExpLock for custom synchronization would silently get no protection.

How

  • Remove the impossible $forks::threads condition from share() call
  • Fix mode check from 'threads' to 'ithreads' in Accept() and t/server
  • Switch PID file from two-arg open(OUT, ">$pidfile") to three-arg open($fh, '>', $pidfile) using the $fh that was already allocated but unused
  • Remove shadowed my $gid/my $uid declarations

Testing

All 67 tests pass. Ithread tests skipped on this system (no ithreads available) — CI will verify the ithreads code path.

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 15 insertions(+), 18 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

toddr-bot and others added 3 commits March 23, 2026 04:30
Two bugs made the regex thread-safety lock completely non-functional:

1. threads::shared::share($RegExpLock) was gated by $forks::threads,
   which is always false when using real ithreads (the $use_ithreads
   guard already excludes forks.pm). The variable was never shared.

2. The lock acquisition in Accept() and t/server checked
   $self->{'mode'} eq 'threads', but the mode value has been
   'ithreads' (not 'threads') since ithreads support was added.
   The lock was never acquired.

Fix: share() unconditionally when ithreads are loaded, and correct
the mode string to 'ithreads' in both Accept() and t/server.

Note: on modern Perl (5.10+ required for ithreads in this code),
regex is thread-safe, so this lock is defensive rather than critical.
But it should work correctly for any subclass that relies on it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- PID file open used two-arg form with bare OUT filehandle despite
  having $fh from Symbol::gensym() already available. Switch to
  three-arg open($fh, '>', $pidfile) which is safer against
  metacharacter injection in the pidfile path.

- Remove unused outer my $gid and my $uid declarations that were
  shadowed by identically-named variables in the inner if blocks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- The DESCRIPTION still referenced Perl 5.005/5.004 as design targets;
  the module requires 5.006 and ithreads need 5.10+
- The --mode documentation mentioned --mode=threads which is not a
  recognized mode value (would produce a fatal error)
- Updated the regex lock comment from the 5.00502 era to reflect
  that modern Perl has thread-safe regex

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant