Skip to content

fix: check subprocess exit codes in Java tracer#2064

Open
mashraf-222 wants to merge 1 commit intomainfrom
fix/tracer-subprocess-exit-codes
Open

fix: check subprocess exit codes in Java tracer#2064
mashraf-222 wants to merge 1 commit intomainfrom
fix/tracer-subprocess-exit-codes

Conversation

@mashraf-222
Copy link
Copy Markdown
Contributor

Problem

_run_java_with_graceful_timeout() in tracer.py discarded the subprocess exit code entirely. In the no-timeout path, subprocess.run() was called with check=False and the result was thrown away. In the timeout path, proc.wait() was called but proc.returncode was never checked.

If Maven or Gradle failed (compilation error, OOM, missing dependency), the tracer silently continued with missing or stale data.

Root Cause

Two bugs in _run_java_with_graceful_timeout():

  • Line 28-29: subprocess.run(java_command, env=env, check=False) — no result captured
  • Lines 34-47: proc.wait() called but proc.returncode never inspected

Fix

  • _run_java_with_graceful_timeout() now returns int (exit code) instead of None
  • Returns -1 for timeout kills (process was forcibly terminated)
  • Logs warnings on non-zero exit codes
  • JavaTracer.trace() handles exit codes per stage:
    • Stage 1 (JFR profiling): Warns and continues (JFR data is supplementary)
    • Stage 2 (argument capture): Raises RuntimeError (trace data is essential)

Test Coverage

10 new tests in test_tracer_exit_codes.py:

  • 7 unit tests for _run_java_with_graceful_timeout() return values (success, failure, OOM, timeout, SIGTERM/SIGKILL)
  • 3 integration tests for JavaTracer.trace() caller behavior (Stage 1 fail continues, Stage 2 fail raises, both succeed)

Testing

$ uv run pytest tests/test_languages/test_java/test_tracer_exit_codes.py -v
10 passed

$ uv run pytest tests/test_languages/test_java/test_java_tracer_e2e.py -v
8 passed (existing integration tests — no regressions)

_run_java_with_graceful_timeout() discarded the subprocess exit code in
both the no-timeout and timeout paths. If Maven/Gradle failed (compilation
error, OOM, etc.), the tracer silently continued with missing/stale data.

Now returns the exit code. Stage 1 (JFR profiling) warns on failure but
continues. Stage 2 (argument capture) raises RuntimeError since trace
data is essential for replay test generation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant