Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test suite fails with perl 5.39.4+ #14

Open
eserte opened this issue Dec 22, 2023 · 14 comments · May be fixed by #15 or #16
Open

Test suite fails with perl 5.39.4+ #14

eserte opened this issue Dec 22, 2023 · 14 comments · May be fixed by #15 or #16

Comments

@eserte
Copy link

eserte commented Dec 22, 2023

See subject, and see http://matrix.cpantesters.org/?dist=Promise-ES6+0.28 for an overview.
Feel free to open a BBC if you think that bleadperl does not behave correctly here.

@FGasper
Copy link
Owner

FGasper commented Dec 22, 2023

@eserte It looks like something changed (broke?) handling of DESTROY.

I may not have the bandwidth to diagnose the issue myself, unfortunately.

@eserte
Copy link
Author

eserte commented Dec 23, 2023

Ah, it's already known: Perl/perl5#21524

@tonycoz
Copy link

tonycoz commented Feb 12, 2024

The issue is that a change around 5.18 broke the documented behaviour of eval EXPR in package DB by not maintaining the OUTSIDE links for each closure.

This means that with the way the failing Promise::ES6 test works you can end up with a reference loop between the closures and (I think) the @resolves array.

This can be avoided in the test by not making the outer scopes visible, for example

--- a/t/race_async.t
+++ b/t/race_async.t
@@ -13,6 +13,32 @@ use PromiseTest;
 
 use Promise::ES6;
 
+sub _bind {
+    my ($sub, @args) = @_;
+
+    return sub {
+        $sub->(@args, @_);
+    };
+}
+
+sub ready1 {
+    my ($eventer, $resolve) = @_;
+
+    if ($eventer->has_happened('ready1') && !$eventer->has_happened('resolved1')) {
+        $resolve->(1);
+        $eventer->happen('resolved1');
+    }
+}
+
+sub ready2 {
+    my ($eventer, $resolve) = @_;
+
+    if ($eventer->has_happened('ready2') && !$eventer->has_happened('resolved2')) {
+        $resolve->(2);
+        $eventer->happen('resolved2');
+    }
+}
+
 {
     my $eventer = Eventer->new();

though there may be prettier fixes.

I asked on the list to see if anyone else had any ideas but didn't receive any solutions.

@akarelas
Copy link

Tests don't pass on perl v5.40.0 either.

@FGasper
Copy link
Owner

FGasper commented Jul 27, 2024

I haven't taken the time to dig into this and am unlikely to do so. (Too many other priorities, sorry.)

I could:

  • just skip this test in 5.39+. (Easy but undesirable long-term.)
  • wait for a PR that fixes the problem, assumedly using @tonycoz's suggested approach.

Any other ideas?

tonycoz added a commit to tonycoz/p5-Promise-ES6 that referenced this issue Aug 1, 2024
This solution works by making the event handlers not closures.

Fixes FGasper#14
tonycoz added a commit to tonycoz/p5-Promise-ES6 that referenced this issue Aug 1, 2024
This solution works by breaking the loop between @resolves, and the
closures the objects it contains, contain

Fixes FGasper#14
@tonycoz
Copy link

tonycoz commented Aug 1, 2024

I've made PRs #15 and #16 with possible solutions.

@akarelas
Copy link

@tonycoz I noticed all your changes were in the test scripts. Does that mean that I should install and use Promise::ES6 on perl v5.40 if I need it, skipping tests, and it should work perfectly?

@FGasper
Copy link
Owner

FGasper commented Aug 13, 2024

@tonycoz Thank you for your PRs.

I hesitate, though, to merge them because they seem to solve the problem in ways that no pure-Perl programmer (i.e., someone who doesn’t grok Perl internals) would reasonably understand. Are the “OUTSIDE links for each closure” an implementation detail of Perl?

Is that correct? If so, would a fix to the interpreter be possible so that pure-Perl code won’t encounter this problem?

@tonycoz
Copy link

tonycoz commented Aug 19, 2024

I hesitate, though, to merge them because they seem to solve the problem in ways that no pure-Perl programmer (i.e., someone who doesn’t grok Perl internals) would reasonably understand. Are the “OUTSIDE links for each closure” an implementation detail of Perl?

Is that correct? If so, would a fix to the interpreter be possible so that pure-Perl code won’t encounter this problem?

The problem is a reference loop.

5.18 broke the reference loop allowing your test to pass, but broke the documented eval "" in package DB behaviour that the debugger depends on, by removing the reference held by subs containing no normal eval on their containing scope.

5.39.4 fixed that documented behaviour, but that means all subs, not just those with evals, need to keep a reference to their containing scope.

This meant that the reference loop which your test documented as fixed in 5.18 was reinstated in 5.39.4.

I spent a lot of time trying to find a solution, including asking on the p5p list, but didn't receive any feedback with a solution.

So I went with the fix to the documented behaviour.

@FGasper
Copy link
Owner

FGasper commented Aug 19, 2024 via email

@jkeenan
Copy link

jkeenan commented Sep 17, 2024

This makes sense; thank you for clarifying. For posterity, though: where is it documented that subs retain a reference to their containing scope?

It appears that @FGasper is still waiting for an answer to a question that was garbled in the GH interface. @tonycoz, can you clarify? (I'd like to see if we can close Perl/perl5#21524.) Thanks.

@tonycoz
Copy link

tonycoz commented Sep 17, 2024

The PSC said:

* We took another brief look at the closure memory leak which is now            
  <https://github.com/Perl/perl5/issues/22547> and resolved to prepare          
  to put down a consensus next time we meet.                                    

so I'm waiting on that.

@toddr
Copy link

toddr commented Nov 13, 2024

@tonycoz any update?

@toddr
Copy link

toddr commented Nov 13, 2024

It looks like discussions are still in progress to revert the change to perl. It still means this module is going to be broken on 5.40.0 but I'm trying the patch to see if it resolves this completely Perl/perl5#22635

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants