Medusa audit wrappers recurse into themselves on both backends

Open
#1,448 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
java, perl
Domain
backend, compilers

Research direction

Start in Medusa.pm around MODIFY_CODE_ATTRIBUTES and line 166, then run the existing suite on both the JVM and interpreter backends to observe the recursion after the first three tests. Add the requested project-owned regression coverage for one wrapper invocation and an original call count of one, while keeping issue #1222's deep-recursion warning behavior independently testable.

Written by the indexing model from the issue text.

Description

area:backend area:cpan-port area:runtime bug

Summary

Medusa 0.05 enters runaway recursion under PerlOnJava when an :Audit-wrapped subroutine invokes the captured original code reference. The upstream suite passes completely under system Perl.

This is distinct from issue #1222: #1222 covers missing Perl-compatible warning delivery for finite recursion, while this failure does not complete because the wrapper repeatedly calls itself.

Reproduction

CPAN random tester run: 20260918-141920-96054

Distribution: Medusa 0.05

The exact missing prerequisites were installed into an isolated library for the system-Perl comparison:

  • Data::UUID 1.227
  • Data::GUID 0.051

(Sub::Exporter and Sub::Install were already available from system Perl.)

System Perl 5.42.2:

All tests successful.
Files=12, Tests=55
Result: PASS

PerlOnJava JVM backend:

t/00-load.t ............. ok
t/01-logger.t ........... ok
t/02-medusa-import.t .... ok
Deep recursion on subroutine "__ANON__" at Medusa.pm line 166.

The test process does not complete within the bounded tester timeout. The interpreter backend reproduces the same warning and nontermination after the same three tests.

Relevant code

Medusa.pm installs an anonymous wrapper from MODIFY_CODE_ATTRIBUTES:

*{"${caller}::$meth"} = sub {
    ...
    my @out = $code->(@_);
    ...
    return wantarray ? @out : shift @out;
};

The failure occurs at the $code->(@_) call (line 166). Under native Perl, $code continues to refer to the original subroutine. Under PerlOnJava, the captured reference appears to resolve back to the newly installed wrapper, causing recursive self-invocation.

Impact

Modules using Perl code attributes and runtime subroutine replacement can hang or hit the tester timeout on both PerlOnJava execution backends. The failure affects normal Medusa audit behavior, not merely warning formatting.

Expected behavior

The wrapper should invoke the original subroutine exactly once, log its return value, and allow the remaining Medusa tests to complete. The captured code reference must remain stable after the package symbol is replaced.

Please add a focused project-owned regression test for wrapping a subroutine through MODIFY_CODE_ATTRIBUTES, invoking the wrapper, and confirming that the original implementation is called once on both JVM and interpreter backends. Also verify that the related deep-recursion warning behavior in issue #1222 remains independently testable.

Dominant language
Perl
Stars
64
Forks
6
Avg merge
5h 25m
Merged PRs (30d)
157

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fglock/PerlOnJava

All issues in fglock/PerlOnJava

Similar issues

More Perl issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.