-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-58956: Fix a frame refleak in bdb #128190
Open
gaogaotiantian
wants to merge
2
commits into
python:main
Choose a base branch
from
gaogaotiantian:fix-bdb-frame-leak
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.
+54
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2024-12-23-02-09-44.gh-issue-58956.4OdMdT.rst
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixed a frame reference leak in :mod:`bdb`. |
Oops, something went wrong.
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.
Should this be in a
finally
block?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.
Theoretically, it's safer to put it in a try finally block. I did not do it for two reasons:
I suggest that we do it in the future when there is a possible exception trigger. Or at least after the backport.
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.
Not sure I see how putting this in a finally makes any difference w.r.t to backporting?
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.
The code diff would be a bit more and we would have an extra indentation.
Currently, all the
finally
in bdb/pdb protect exceptions from user code, not the debugger code. If we set a precedence to assume every line of code can generate an exception and we have to make sure everything, including references, needs to be properly released, we would be in a giant hole.For example, we are holding a frame reference in
self.returnframe
, which is set by_set_stopinfo
. And the way we release it, is when we do acontinue
,set_continue
would set it toNone
. But what if there's a random exception somewhere? Do we protect that with afinally
?We are also using the frame as a key in
self.frame_trace_line_opcodes
, thus keeping a reference to it, which will also be released inset_continue
as long as there are no breakpoints, do we protect those as well (it's right before the next change)? If so, we have two resources to release, do we doI think my point is - the debugger should not crash. If it crashes by itself, we don't really care about reference leaks, we should fix the debugger. Therefore, we should only care about exceptions from the user code and make sure resources are released in those cases.
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.
self.frame_trace_lines_opcodes
can be cleared in the same finally. Anyway, up to you.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.
Right, we normally assume
self.frame_trace_lines_opcodes = {}
won't raise an exception - that's why we can put them together in the samefinally
. I think we should do the same for most of the internal debugger code - unless it's very critical. That's how pdb/bdb does it for now. It assumes the debugger code works (at least the simple ones) and release resources accordingly.In
set_trace
, the code between settingenter_frame
and releasingenter_frame
are basically all assignments (includingset_stepinstr
), so we can assume that no exception will be raised (otherwiseself.frame_trace_lines_opcodes = {}
is not safe either).As for
set_continue
, we actually can't prevent the leak from happening if there's a crash in the debugger, because that means it's possible to break out of the debugger without runningset_continue
. We now assume the user always gets a chance to runcontinue
, which would release the reference - that might not be the case if we consider the possibility of a debugger crash. Then our protection to ensure the release happens inset_continue
does not do much.