-
Notifications
You must be signed in to change notification settings - Fork 582
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
__SUB__ references wrong callback, we must use outer callback #1783
Open
Sadrak
wants to merge
1
commit into
mojolicious:main
Choose a base branch
from
Sadrak:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this cleaner than
my $fetch; $fetch = sub {
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, i am lost.
I simple wanted to fix a bug in the documentation. My initial fix was not accepted, because of a newly introduced memleak.
The optimized non-memleak variant has now the problem it looks to similar to the memleak-variant?
Can someone please help me and tell me what exactly is required to fix this bug? I wanted a minimalistic change not a complete rewrite of the example.
Next try would be to rename the inner $fetch to something else, can someone please suggest a name, i am tired of trying to help ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then just don't use
__SUB__
in an example where it serves no purpose.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't want to figure out the correct solution, please open an issue instead of a PR in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jhthorsen can you please confirm the difference between
my $fetch ; $fetch = sub { ...
andmy $fetch = sub { ... my $fetch = __SUB__; ...
In my understanding the later (current MR) will not leak a reference after the
$promise->wait;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sadrak
If I understand correctly, they are looking for:
$fetch
must be declared first, and then assigned to, so that it is available within the function. If it was assigned during the declarationmy $fetch = sub { ...
then$fetch
would not be available within the body of the function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty sure this solution get a downvote from @jhthorsen (that was my first try).
And he is absolut right.
So to resume: The documentation is broken. I tried to figure this out, but can't get a proper/accepted solution. Next step is what? I guess closing and ignoring? :-/ That hurt in my developer heart ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lost track of the history of this discussion and have no idea what @jhthorsen was referring to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using
my $fetch ; $fetch = sub { ...; $fetch->(); ...; }
will leak one reference.$fetch
won't cleaned up after the scope due to a circular reference.Alternatively before calling
$promise->resolve
we have to callundef $fetch
manually to break the circular reference.Or use the current MR with
my $fetch = __SUB__
as a solution to this problem.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my testing so far,
my $fetch; $fetch =
is flagged as circular byDevel::Cycle
. But then so is $ua. Declaringmy $fetch = __SUB__
within the sub does remove that circular reference, but$ua
remains unless it is passed in as an argument, e.g.I'm still testing for alternatives, and also to understand why the above example finishes with a high refcount, whereas the version with
my $fetch; $fetch =
finishes with a refcount of 1.