Skip to content

Leak tests fail on CPAN testers (zz-grammar-factory-leak, zz-process-leak) #442

Description

@toddr-bot

Problem

The memory leak tests t/zz-grammar-factory-leak.t and t/zz-process-leak.t fail on CPAN testers running with AUTOMATED_TESTING=1 and Test::LeakTrace installed.

Affected reports (3.106):

Both reports show identical failures:

Test file Failed Total Details
t/zz-grammar-factory-leak.t 4 8 tests 3-6 (all no_leaks_ok calls)
t/zz-process-leak.t 3 6 tests 1, 3, 5 (all no_leaks_ok calls)

Details

Every no_leaks_ok block detects 3 leaked SVs per Template->new() + process() cycle. The leak diagnostic output identifies leaked SVs originating from:

  1. Template::Grammar->new() (Parser.pm:179) — Grammar singleton re-creation
  2. $CONTEXT->new($params) (Config.pm:234) — Context object allocation
  3. split(/$dlim/, $path) (Provider.pm:340) — REGEXP SV from INCLUDE_PATH delimiter

The factory cleanup fix from PR #344 (commit 6f8ba8c) added reference-counting to the Grammar $factory singleton. However, this causes the factory to be freed and re-allocated on each Template lifecycle rather than remaining a persistent singleton, which means Test::LeakTrace sees new allocations on every cycle. The other two leak sources (Config, Provider) were not addressed by PR #344.

Why most PASS reports don't catch this

Both tests are gated behind AUTOMATED_TESTING || RELEASE_TESTING and require Test::LeakTrace to be installed. Most CPAN testers in the PASS matrix likely skip these tests entirely. The failing testers (ANDK, BINGOS) are known automated smoke testers who set AUTOMATED_TESTING=1 and have Test::LeakTrace available.

Possible fixes

  1. Fix the underlying leaks — Track down why 3 SVs survive each Template processing cycle and ensure proper cleanup. The $factory reference-counting logic in Grammar.pm may need to avoid freeing the singleton so it remains a one-time allocation.
  2. Guard with --dev flag — If the leaks are known/acceptable, gate these tests behind $ENV{AUTHOR_TESTING} or $ENV{RELEASE_TESTING} only (remove AUTOMATED_TESTING) so they don't cause FAIL reports from automated smokers.
  3. Use leaks_cmp_ok with a tolerance — Replace no_leaks_ok with leaks_cmp_ok { ... } '<=', 3 to allow the known singleton allocation while still catching regressions.

🤖 Created by Kōan from CPAN tester failure analysis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions