Skip to content

_remote_debugging: Invalid RLE count XXX exceeds maximum possible XXX for remaining data #149342

@maurycy

Description

@maurycy

Bug report

Bug description:

Found while profiling the whole -m test...

There are two issues here:

  • Invalid RLE count
  • incorrect samples count (129088 v. 129091)

Real reproduction that I encountered

[1] 2026-05-04T03:23:50.414056000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (main 2e94f14) % sudo -E /Users/maurycy/src/github.com/maurycy/cpython/python.exe \
    -m profiling.sampling run \
    --sampling-rate 1000000 \
    --duration 60 \
    --binary -o /tmp/repro.bin \
    -m test test_asyncio.test_base_events
Using random seed: 1964393136
0:00:00 load avg: 2.44 Run 1 test sequentially in a single process
0:00:00 load avg: 2.44 [1/1] test_asyncio.test_base_events
0:00:01 load avg: 2.32 [1/1] test_asyncio.test_base_events passed

== Tests result: SUCCESS ==

1 test OK.

Total duration: 1.5 sec
Total tests: run=116 skipped=1
Total test files: run=1/1
Result: SUCCESS
Captured 143,113 samples in 1.57 seconds
Sample rate: 91,375.80 samples/sec
Error rate: 9.80
  Binary Encoding:
    Records:          12,013
      RLE repeat:     1,023 (8.5%) [118,098 samples]
      Full stack:     3 (0.0%)
      Suffix match:   1,513 (12.6%)
      Pop-push:       9,474 (78.9%)
  Frame Efficiency:
    Frames written:   24,428
    Frames saved:     4,717,911 (99.5%)
    Bytes (pre-zstd): 473.3 KB
Warning: missed 1423089 samples from the expected total of 1566202 (90.86%)
Binary profile written to /tmp/repro.bin (129088 samples)
2026-05-04T03:23:52.834435000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (main 2e94f14) % /Users/maurycy/src/github.com/maurycy/cpython/python.exe \
  -m profiling.sampling replay --collapsed \
  -o /tmp/out.collapsed /tmp/repro.bin
Replaying 129091 samples from /tmp/repro.bin
  Sample interval: 1 us
  Compression: zstd
  [███████████████████████████████████████░] 100.0% (129,066/129,091)Error: Invalid RLE count 1566628 exceeds maximum possible 10 for remaining data

Repro from my dump

2026-05-04T03:28:27.980622000+0200 maurycy@gimel /Users/maurycy/work/cpython (main 2e94f14) % curl -sL https://gist.githubusercontent.com/maurycy/ca583d26ddf87794c8d25c9719786940/raw | base64 -d > repro.bin
2026-05-04T03:28:33.775531000+0200 maurycy@gimel /Users/maurycy/work/cpython (main 2e94f14?) % ./python.exe -m profiling.sampling replay --collapsed -o /tmp/out.collapsed repro.bin
Replaying 129091 samples from repro.bin
  Sample interval: 1 us
  Compression: zstd
  [███████████████████████████████████████░] 100.0% (129,066/129,091)Error: Invalid RLE count 1566628 exceeds maximum possible 10 for remaining data

Targeted reproduction

import _remote_debugging
w = _remote_debugging.BinaryWriter('/tmp/test.bin', 1, 1000000, compression=0)
loc = _remote_debugging.LocationInfo((10, 10, 0, 0))
fi = _remote_debugging.FrameInfo(('foo.py', loc, 'bar', None))
w.write_sample([_remote_debugging.InterpreterInfo((0, [_remote_debugging.ThreadInfo((12345, 1, [fi]))]))], 1000001)
# new thread with empty stack...
try:
    w.write_sample([_remote_debugging.InterpreterInfo((0, [_remote_debugging.ThreadInfo((99999, 4, []))]))], 1000004)
except RuntimeError as e:
    print(e)  # "Invalid stack encoding type" - smashed already.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions