Skip to content

Don't block the tracked program on stderr in run --live - #1102

Merged
godlygeek merged 1 commit into
bloomberg:mainfrom
patrick-immometrica:fix-live-stderr-deadlock
Nov 25, 2026
Merged

godlygeek merged 1 commit into
bloomberg:mainfrom
patrick-immometrica:fix-live-stderr-deadlock

Conversation

@patrick-immometrica

Copy link
Copy Markdown
Contributor

memray run --live started the tracked program with stderr=subprocess.PIPE, and nothing read the pipe until the TUI exited. A program that writes more than the pipe buffer (64 KiB on Linux) to stderr blocks in write() and stops running, while the TUI keeps showing the frozen heap.

The child's stderr now goes to a tempfile.TemporaryFile(), which is read back and printed when the child exits with an error, the same as before.

The new integration test runs a script that writes about 250 KB to stderr, touches a marker file and exits with 1. It checks that the marker was created and that the last line shows up in memray's stderr. Without the fix, the marker never shows up. The two unit tests that checked stderr=-1 in the Popen call now accept any value there.

Closes: #1098

@patrick-immometrica
patrick-immometrica marked this pull request as ready for review November 24, 2026 21:44
@codecov-commenter

codecov-commenter commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.75862% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.37%. Comparing base (bc9b7bc) to head (3beac65).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
tests/integration/test_main.py 87.50% 3 Missing ⚠️
src/memray/commands/run.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1102      +/-   ##
==========================================
- Coverage   92.38%   92.37%   -0.02%     
==========================================
  Files         103      103              
  Lines       13506    13532      +26     
  Branches      483      484       +1     
==========================================
+ Hits        12478    12500      +22     
- Misses       1028     1032       +4     
Flag Coverage Δ
cpp 92.37% <82.75%> (-0.02%) ⬇️
python_and_cython 92.37% <82.75%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@godlygeek
godlygeek force-pushed the fix-live-stderr-deadlock branch from 42e77a2 to 5705347 Compare November 25, 2026 22:37
The child process started by `memray run --live` wrote its stderr into
a pipe that nobody read until the TUI exited. If the program wrote
enough to fill the pipe buffer (about 64 KiB on Linux), it blocked in
`write()` and stopped making progress.

Send its stderr to a temporary file instead, and read that back when
the child fails, so the error output is still shown.

Signed-off-by: Patrick Hintermayer <patrick@immometrica.com>
@godlygeek
godlygeek force-pushed the fix-live-stderr-deadlock branch from 5705347 to 3beac65 Compare November 25, 2026 22:39

@godlygeek godlygeek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the contribution @patrick-immometrica!

I switched the test up to use a FIFO opened and written to by the child process but never closed, so that we can detect the child having already died based on getting an EOF on that FIFO. As the test was originally written, we might send the q while the program was still running, or we might send it after the program had exited. Now we are guaranteed to only send it once the program has exited.

@godlygeek
godlygeek enabled auto-merge (rebase) November 25, 2026 22:44
@godlygeek
godlygeek merged commit 6deb22c into bloomberg:main Nov 25, 2026
16 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memray run --live freezes the script after ~64 KiB of stderr output

3 participants