Skip to content

[interpreter] Capture::Tiny fails when duplicating STDOUT during capture #2015

Open

Description

@fglock

Summary

Capture::Tiny output capture fails on the PerlOnJava interpreter. Duadua 0.36's t/50_cli.t uses Capture::Tiny and exits before completing its assertions when run with the interpreter. The same test passes under system Perl and the PerlOnJava JVM backend.

This was found while investigating CPAN random run 20261109-091152-39587. That run's archived default-backend log ends after t/15_reparse.t without a harness summary, so its Unknown test outcome is inconclusive and is not evidence for this interpreter failure. The full Duadua suite passes under system Perl and under the default PerlOnJava launcher/JVM backend (6 files, 490 tests).

Minimal reproducer

use Capture::Tiny qw(capture);
my ($stdout, $stderr) = capture { print "captured\n" };
die "unexpected capture: $stdout" unless $stdout eq "captured\n";
die "unexpected stderr: $stderr" if length $stderr;
print "capture ok\n";

Run the program with system Perl, the PerlOnJava JVM backend, and the PerlOnJava interpreter backend.

Results

  • System Perl 5.42.2: prints capture ok and exits 0.
  • PerlOnJava JVM backend: prints capture ok and exits 0.
  • PerlOnJava interpreter backend: fails before the capture callback completes with Bad file descriptor while Capture::Tiny duplicates STDOUT.
  • Duadua 0.36 t/50_cli.t: passes under system Perl and the JVM backend; under the interpreter it exits with status 255 after 9 assertions, before done_testing.

The failing call path is Capture::Tiny::_capture_tee -> _open_std -> _open. _open_std opens STDOUT in dup mode (>&); _open reports the bad descriptor. The reproducer uses the pure-Perl Capture::Tiny 0.50 module.

Environment

  • macOS 26.7.1
  • OpenJDK 24.0.2 (Temurin)
  • PerlOnJava launcher built from local master commit 13db7bd4a0 (2026-11-05)
  • Duadua 0.36; Capture::Tiny 0.50

Related issue

Issue #1165 fixed duplication of a tied filehandle. This reproducer is a separate interpreter failure in Capture::Tiny's ordinary capture path; the JVM backend succeeds.

Acceptance criteria

  • The minimal reproducer succeeds on both PerlOnJava backends and system Perl.
  • Duadua 0.36 t/50_cli.t and the full upstream suite pass under the interpreter.
  • Add a focused project-owned regression test validated with system Perl first.

Activity

  1. added
    bug
    area:io
    area:backend
    on Nov 10, 2026
  2. fglock commented on Nov 11, 2026

    @fglock
    OwnerAuthor

    State: active
    Agent/session: codex-root-io-2024-2023-2015-2018-20261111
    Scope: #2024, #2023, #2015, #2018; bundled IO::Handle load warnings, File::Temp IPC::Run3 spooling, interpreter STDOUT duplication, and shebang trailing semicolon launch behavior, with project regression tests.
    Work: fix/io-handles-script-launch-2015-2024, source 0c06151; no PR yet.
    Checkpoint: 2026-11-11; reports are open and current issue bodies contain no comments or claims. No linked issue-specific PR found in the initial title search. Investigating code paths and independent acceptance tests.
    Evidence: issue reports #2024/#2023/#2015/#2018; source checkout 0c06151.
    Blocked by: none known. #2023 notes possible relation to #1649 but no prerequisite is established.
    Next: reproduce on the current source, implement focused fixes and tests, validate against system Perl and both PerlOnJava backends.

  3. fglock commented on Nov 11, 2026

    @fglock
    OwnerAuthor

    Related to #2023 within CPAN run 20261109-091152-39587: both affect subprocess I/O, but by distinct mechanisms. #2023 fails while spooling scalar input through File::Temp and IPC::Run3; this issue fails when the interpreter duplicates STDOUT for Capture::Tiny. The #2023 resource-lifetime path is also an acceptance case for #1649, but this descriptor-duplication issue is not dependent on that broader ownership project. #2024 and #2018 are separate module-load warning and shebang parsing findings from the same run.

  4. fglock commented on Nov 11, 2026

    @fglock
    OwnerAuthor

    Update from the focused reproducer: the interpreter failure occurs when File::Temp->new is stored through a nested ||= hash assignment; the resulting handle's fileno becomes undef before Capture::Tiny redirects STDOUT. This is a concrete hash-slot/resource-lifetime case related to #1649's ownership work, superseding the earlier note that this descriptor-duplication issue was not dependent on that project. #2023 also exercises File::Temp handles, but its current IPC::Run3 scalar-spooling reproducer passes on both backends after stdin forwarding, so a shared root cause with this issue remains unproven.

  5. fglock commented on Nov 11, 2026

    @fglock
    OwnerAuthor

    Current status (2026-11-11)

    The independent fixes for #2018, #2023, and #2024 are in PR #2035, rebased on current master and locally validated with make and make check-links.

    The #2015 reproducer still fails on the interpreter when a File::Temp object is stored through nested ||= hash assignment: its fileno becomes undefined before Capture::Tiny redirects STDOUT. This is the hash-slot/resource lifetime behavior tracked in #1649. Per the requested dependency, implementation of this part is deferred until #1649 is complete. #1649 remains open; its current PR #1938 is also marked unmergeable, so there is no completed ownership fix to build on yet.

  6. fglock commented on Nov 11, 2026

    @fglock
    OwnerAuthor

    Follow-up after PR #2035 merged (2026-11-11)

    PR #2035 merged as daa2d54d81b430f7185a69b0f1614dc4577ffdf8; it resolves the independent #2018, #2023, and #2024 findings. This issue remains open and is not fixed by that PR.

    The interpreter reproducer still loses fileno for a File::Temp object stored through nested ||= hash assignment before Capture::Tiny redirects STDOUT. This is the hash-slot/resource lifetime behavior tracked by #1649. As agreed, implementation remains deferred until #1649 is complete. #1649 is still open, and its current PR #1938 is open with merge state unknown.

  7. fglock commented on Nov 12, 2026

    @fglock
    OwnerAuthor

    Dependency update (2026-11-12)

    The #2015 reproducer still loses fileno for a File::Temp object stored through nested ||= hash assignment before Capture::Tiny redirects STDOUT. This remains a resource-lifetime/ownership case. The prior comments refer to #1649, which is now closed; the active successor work is #2043, with its current implementation tracked in draft PR #1938.

    Implementation and acceptance reruns for this case remain deferred until #2043 delivers or hands off the relevant owner-slot behavior. This updates the dependency reference; it does not claim the issue is fixed.

  8. added
    blocked:ownership
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:backendarea:ioblocked:ownershipbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions