-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-151292: _remote_debugging: Do not corrupt the binary file when hitting OverflowError
#152892
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||||||||||||||||
| """Thin Python wrapper around C binary writer for profiling data.""" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||||||||||
| import time | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import _remote_debugging | ||||||||||||||||||||||||||||||||||
|
|
@@ -61,6 +62,7 @@ def __init__(self, filename, sample_interval_usec, *, skip_idle=False, | |||||||||||||||||||||||||||||||||
| self.filename = filename | ||||||||||||||||||||||||||||||||||
| self.sample_interval_usec = sample_interval_usec | ||||||||||||||||||||||||||||||||||
| self.skip_idle = skip_idle | ||||||||||||||||||||||||||||||||||
| self.running = True | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| compression_type = _resolve_compression(compression) | ||||||||||||||||||||||||||||||||||
| start_time_us = int(time.monotonic() * 1_000_000) | ||||||||||||||||||||||||||||||||||
|
|
@@ -79,9 +81,17 @@ def collect(self, stack_frames, timestamp_us=None): | |||||||||||||||||||||||||||||||||
| timestamp_us: Optional timestamp in microseconds. If not provided, | ||||||||||||||||||||||||||||||||||
| uses time.monotonic() to generate one. | ||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| if not self.running: | ||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||
| if timestamp_us is None: | ||||||||||||||||||||||||||||||||||
| timestamp_us = int(time.monotonic() * 1_000_000) | ||||||||||||||||||||||||||||||||||
| self._writer.write_sample(stack_frames, timestamp_us) | ||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||
| self._writer.write_sample(stack_frames, timestamp_us) | ||||||||||||||||||||||||||||||||||
| except OverflowError as e: | ||||||||||||||||||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pablogsal Truth be told, I'm not 100% sure what's the best layer for handling "finalizable" exceptions like The promise of "finalizing the file" is in the cpython/Modules/_remote_debugging/module.c Lines 1857 to 1864 in 3428959
This is not the case: cpython/Lib/profiling/sampling/binary_collector.py Lines 115 to 120 in 3428959
cpython/Modules/_remote_debugging/module.c Line 1874 in 3428959
Perhaps it's something as simple as weakening This issue presents itself there since we've got both the unwinder and the collector in the bloc : cpython/Lib/profiling/sampling/sample.py Line 180 in 3428959
...and the meaning of Of course - the very proper way to approach this is to maintain the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that the module should own this knowledge, but I don’t think weakening For this PR I’m fine with the collector-level stop, but I’d avoid broadening
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I think for this PR, I’d prefer we make the C writer expose the real state instead of catching broad
|
||||||||||||||||||||||||||||||||||
| self.running = False | ||||||||||||||||||||||||||||||||||
| print(f"Warning: {e}; stopping early and keeping the data " | ||||||||||||||||||||||||||||||||||
| "collected so far.", | ||||||||||||||||||||||||||||||||||
| file=sys.stderr) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def collect_failed_sample(self): | ||||||||||||||||||||||||||||||||||
| """Record a failed sample attempt (no-op for binary format).""" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Fix ``profiling.sampling --binary`` leaving unreadable profile files when | ||
| the ``_remote_debugging`` binary writer raises :exc:`OverflowError`. Patch | ||
| by Maurycy Pawłowski-Wieroński. |
Uh oh!
There was an error while loading. Please reload this page.