Repository navigation
_remote_debugging: raising Invalid bytes length on codeobjects with linetable > 4096 #151022
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jun 6, 2026 cc @pablogsal 2^16 is tempting :-)
640K ought to be enough for anybody
Reacted by Maurycy Pawłowski-Wieroński- addedextension-modulesC modules in the Modules dirC modules in the Modules dir
on Jun 6, 2026 @maurycy I could reproduce this on current main with the html.entities example. The line table is 37445 bytes, so the failure happens before parsing because the remote bytes read is capped at 4096.
I opened #151036 with a narrow fix. It keeps the generic remote bytes reader bounded, but uses a separate larger bound for code object line tables. I also added a regression test that builds a code object with a line table over 4096 bytes and verifies that same-process unwinding succeeds.
- added a commit that references this issue
on Jun 6, 2026 @pablogsal The more I think about this... For the purpose of
mach_vm_remap, I'm trying to measure the bias (ie: delta between the truth and what we report, with aliasing and sampling rates between 2-5MHz I started to wonder about it; spoiler: we're great here.) But the original issue reports heavy bias actually...linetable,qualname/filenameandMAX_FRAMES(and this_sync_coordinator.py; unlucky person who accidentially uses this name too) drop the whole frame silently. Now, for a long-running profiler on a large-scale production system a heavy bias, like the one observed originally, makes the profiling not trustworthy, and time completely wasted. In other words, apart from making the limits realistic, I believe we should not drop the frames on limit but degrade@pablogsal The more I think about this... For the purpose of
mach_vm_remap, I'm trying to measure the bias (ie: delta between the truth and what we report, with aliasing and sampling rates between 2-5MHz I started to wonder about it; spoiler: we're great here.) But the original issue reports heavy bias actually...linetable,qualname/filenameandMAX_FRAMES(and this_sync_coordinator.py; unlucky person who accidentially uses this name too) drop the whole frame silently. Now, for a long-running profiler on a large-scale production system a heavy bias, like the one observed originally, makes the profiling not trustworthy, and time completely wasted. In other words, apart from making the limits realistic, I believe we should not drop the frames on limit but degradeWhat kind of degradation did you have in mind? Emitting the frame with line unknown when the linetable read fails, or something more specific?
@pablogsal The more I think about this... For the purpose of
mach_vm_remap, I'm trying to measure the bias (ie: delta between the truth and what we report, with aliasing and sampling rates between 2-5MHz I started to wonder about it; spoiler: we're great here.) But the original issue reports heavy bias actually...linetable,qualname/filenameandMAX_FRAMES(and this_sync_coordinator.py; unlucky person who accidentially uses this name too) drop the whole frame silently. Now, for a long-running profiler on a large-scale production system a heavy bias, like the one observed originally, makes the profiling not trustworthy, and time completely wasted. In other words, apart from making the limits realistic, I believe we should not drop the frames on limit but degradeWhat kind of degradation did you have in mind? Emitting the frame with line unknown when the linetable read fails, or something more specific?
Yes, only this, truncation or a placeholder in case of
qualname/filenameorMAX_FRAMESetc. I think. More than open for any other ideas.FWIW, when profiling pystone.py1,
python.exe -m profiling.sampling run pystone.py 100000I also get a high error rate (about 30%) on Windows (if that makes a difference).
The attached PR doesn't help, and also from the errors I think this must be something different:
Lots of
Failed to parse initial frame in chain
ReadProcessMemory failed for PID 24180 at address 0xc0000000 (size 64, partial read 0 bytes): Windows error 998
ReadProcessMemory failed for PID 24180 at address 0xe7 (size 64, partial read 0 bytes): Windows error 299Where
ERROR_NOACCESS=998andERROR_PARTIAL_COPY=299, which all indicate reading from invalid memory (already quite obvious from the pointer values).Footnotes
- added a commit that references this issue
on Jul 18, 2026 @chris-eibl Thanks for testing this on Windows. I updated the PR to use a 64 KiB line-table limit and removed the separate entry-count limit.
The
ReadProcessMemoryerrors shown here occur while resolving the initial frame chain, before line-table parsing begins, so they appear to be a separate failure path from the large-line-table issue addressed by #151036.Could you compare the same pystone run with
--blocking? If the errors disappear, that would help determine whether the invalid frame addresses come from a race in the non-blocking snapshot path. I think the Windows frame-chain failure should otherwise be tracked separately so both problems remain independently reproducible. Let me know.
cc @maurycyYeah,
--blockingdrastically reduces the error rate (after applying #152471). And I agree this is a different (and most probably only Windows related) issue.Having a closer look, I think this quote from the documentation
However, non-blocking sampling can occasionally produce incomplete or inconsistent stack traces [...] in programs with very fast-changing call stacks where functions enter and exit between the start and end of a single stack read
very much applies to pystone.py. I've just wondered about the high error rate without giving it a closer thought. Sorry for the noise here ...
Some background from py-spy but the reason the same, IIUC: https://www.benfrederickson.com/why-python-needs-paused-during-profiling/
Bug report
Bug description:
I've reproduced the issue reported in https://discuss.python.org/t/tachyon-97-error-rate/107619
The issue is caused by:
cpython/Modules/_remote_debugging/code_objects.c
Lines 389 to 390 in 884ac3e
The linetable for
HttpCli.tx_browserandHttpCli.runis above 4096:The 4096 limit is too small even for our stdlib:
Reproduction
Using real file from stdlib:
We get:
Bonus
(thx Claude)
linetable_dist.pyCPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs