Skip to content

Fix ArithmeticError in ServeShapePlug when parse_body halts before telemetry span#3929

Open
alco wants to merge 3 commits intomainfrom
worktree-replicated-plotting-bunny
Open

Fix ArithmeticError in ServeShapePlug when parse_body halts before telemetry span#3929
alco wants to merge 3 commits intomainfrom
worktree-replicated-plotting-bunny

Conversation

@alco
Copy link
Member

@alco alco commented Feb 27, 2026

Summary

  • Moved parse_body plug after start_telemetry_span in the pipeline to prevent ArithmeticError when parse_body halts (e.g. oversized body, bad JSON) before the telemetry span is initialized
  • The custom halt/1 calls end_telemetry_span() which tried to compute System.monotonic_time() - nil, crashing the request

Fixes #3919

Test plan

  • Existing serve_shape_plug_test.exs tests pass (31 tests, 0 failures)
  • Add new unit tests that fail without the fix

🤖 Generated with Claude Code

alco and others added 2 commits February 27, 2026 21:18
…meticError

When parse_body halted a request before start_telemetry_span had
executed, the custom halt/1 would call end_telemetry_span which tried
to compute `System.monotonic_time() - nil`, causing an ArithmeticError.

Fixes #3919

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.75%. Comparing base (749fb4d) to head (bb8f525).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3929   +/-   ##
=======================================
  Coverage   75.75%   75.75%           
=======================================
  Files          11       11           
  Lines         693      693           
  Branches      174      172    -2     
=======================================
  Hits          525      525           
  Misses        167      167           
  Partials        1        1           
Flag Coverage Δ
packages/experimental 87.73% <ø> (ø)
packages/react-hooks 86.48% <ø> (ø)
packages/start 82.83% <ø> (ø)
packages/y-electric 56.05% <ø> (ø)
typescript 75.75% <ø> (ø)
unit-tests 75.75% <ø> (ø)

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

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

These tests verify that POST requests with invalid JSON or non-object
JSON bodies return proper 400 responses without crashing. Before the
plug ordering fix, these paths would trigger an ArithmeticError in
end_telemetry_span.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@alco alco marked this pull request as ready for review February 27, 2026 21:23
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.

ArithmeticError in ServeShapePlug.end_telemetry_span/2 when parse_body halts before telemetry span starts

1 participant