Skip to content

ExtUtils::MM_Unix: avoid die in _find_static_libs on removed dirs (fixes #24561) - #24839

Open
goanscryca wants to merge 1 commit into
Perl:bleadfrom
goanscryca:fix/issue-24561
Open

goanscryca wants to merge 1 commit into
Perl:bleadfrom
goanscryca:fix/issue-24561

Conversation

@goanscryca

Copy link
Copy Markdown

Summary

Fixes #24561.

During parallel test runs (such as core smoke tests with multiple jobs), cpan/ExtUtils-MakeMaker/t/03-xsstatic.t could intermittently fail during static makeaperl with errors such as:

Can't cd to .. from ../../../../lib/auto/ExtTest: No such file or directory at ../../../../lib/File/Find.pm line 477.

or

Can't opendir(../../../../lib/auto/ExtTest): Stale file handle
Can't cd to .. from ../../../../lib/auto/ExtTest: Stale file handle at ../../../../lib/File/Find.pm line 477.

Root Cause

Another test running concurrently (such as cpan/ExtUtils-Constant/t/Constant.t) builds and cleans up test modules in the core lib/auto directory (e.g., lib/auto/ExtTest) while 03-xsstatic.t runs make test for a static perl binary.
When staticmake invokes ExtUtils::MM_Unix::_find_static_libs to discover static extension libraries under auto/, File::Find::find was called with default settings (no_chdir => 0).
If a directory under auto/ was deleted concurrently while File::Find was traversing it, File::Find failed when attempting to chdir('..') back to the parent directory and died at line 477.

Solution

  • Run File::Find::find with no_chdir => 1 in _find_static_libs, avoiding directory changes during traversal.
  • Suppress transient traversal warnings with no warnings; within the search scope so removed directories don't emit spurious errors if unlinked right before opendir.
  • Compute paths using abs_path($File::Find::name) / rel2abs rather than relying on cwd().
  • Add test coverage in cpan/ExtUtils-MakeMaker/t/MM_Unix.t simulating concurrent directory removal during _find_static_libs.

During parallel test runs (e.g., core smoke tests), cpan/ExtUtils-MakeMaker/t/03-xsstatic.t
could intermittently fail during static makeaperl with:
  Can't cd to .. from ../../../../lib/auto/ExtTest: No such file or directory at File/Find.pm line 477.
or:
  Can't opendir(../../../../lib/auto/ExtTest): Stale file handle
  Can't cd to .. from ../../../../lib/auto/ExtTest: Stale file handle at File/Find.pm line 477.

This happens because another test running concurrently (such as
cpan/ExtUtils-Constant/t/Constant.t) creates and cleans up modules in the
core lib/auto directory (e.g., ExtTest) while 03-xsstatic.t is running
_find_static_libs. Because File::Find defaulted to chdir'ing into each
directory (no_chdir => 0), when a visited directory was deleted concurrently,
File::Find failed to chdir('..') and died.

Fix by running File::Find::find with no_chdir => 1 and disabling File::Find
warnings, preventing chdir into subdirectories and safely ignoring directories
that vanish during traversal.

Fixes Perl#24561.
return unless -f 'extralibs.ld'; # this checks is a "proper" XS installation
return unless -f "$File::Find::dir/extralibs.ld"; # this checks is a "proper" XS installation

my ($base) = $File::Find::name =~ m{([^/\\]+)\z};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File::Basename::basename?

@jkeenan

jkeenan commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #24561.

During parallel test runs (such as core smoke tests with multiple jobs), cpan/ExtUtils-MakeMaker/t/03-xsstatic.t could intermittently fail during static makeaperl with errors such as:

Can't cd to .. from ../../../../lib/auto/ExtTest: No such file or directory at ../../../../lib/File/Find.pm line 477.

or

Can't opendir(../../../../lib/auto/ExtTest): Stale file handle
Can't cd to .. from ../../../../lib/auto/ExtTest: Stale file handle at ../../../../lib/File/Find.pm line 477.

Root Cause

Another test running concurrently (such as cpan/ExtUtils-Constant/t/Constant.t) builds and cleans up test modules in the core lib/auto directory (e.g., lib/auto/ExtTest) while 03-xsstatic.t runs make test for a static perl binary. When staticmake invokes ExtUtils::MM_Unix::_find_static_libs to discover static extension libraries under auto/, File::Find::find was called with default settings (no_chdir => 0). If a directory under auto/ was deleted concurrently while File::Find was traversing it, File::Find failed when attempting to chdir('..') back to the parent directory and died at line 477.

I can't claim deep expertise in this area and have not yet evaluated the p.r., but I do note that our smoke-test reports show intermittent failures to complete ./cpan/ExtUtils-MakeMaker/t/03-xsstatic.t:

Among the above reports, the following reports also showed premature exits in ../cpan/ExtUtils-MakeMaker/t/02-xsdynamic.t:

@bingos @toddr

@jkeenan

jkeenan commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

@goanscryca, thank you for your patch. Since ExtUtils-MakeMaker is primarily maintained upstream on CPAN, it will have to be evaluated by the maintainers of that CPAN library. To get the ball rolling on that, I have filed Perl-Toolchain-Gang/ExtUtils-MakeMaker#488; you should follow that ticket.

When we ran your pull request through our CI system, we noted two porting test (metadata) failures: one in t/porting/cmp_version.t -- which the upstream maintainers can handle -- and one in t/porting/authors.t. With respect to the latter, we need to add your name and email address to AUTHORS. For this purpose we strongly prefer your real name (i.e., not just a GH handle) and an email address at which we can reach you over the long-term (i.e., something other than NAME@users.noreply.github.com. In your GH checkout, please run perl Porting/updateAUTHORS.pl and supply your name and valid email address.

As noted in posts above, we have identified smoke-test reports with the test failures you have reported. For diagnostic purposes we'll be running additional smoke-tests on a branch created from your pull request.

@Leont

Leont commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

@goanscryca, thank you for your patch. Since ExtUtils-MakeMaker is primarily maintained upstream on CPAN, it will have to be evaluated by the maintainers of that CPAN library. To get the ball rolling on that, I have filed Perl-Toolchain-Gang/ExtUtils-MakeMaker#488; you should follow that ticket.

Yeah, this should be closed here and opened in ExtUtils::MakeMaker's repository.

@Leont

Leont commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Another test running concurrently (such as cpan/ExtUtils-Constant/t/Constant.t) builds and cleans up test modules in the core lib/auto directory (e.g., lib/auto/ExtTest) while 03-xsstatic.t runs make test for a static perl binary.

This OTOH sounds like it's ExtUtils::Constant that should do something more sensible.

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.

cpan/ExtUtils-MakeMaker/t/03-xsstatic.t: intermittent test failure on -DDEBUGGING builds

4 participants