Skip to content

Fix JSRPC Return event timing to fire when handler returns#5721

Merged
danlapid merged 1 commit intomainfrom
dlapid/fix_jsrpc_return_event
Dec 18, 2025
Merged

Fix JSRPC Return event timing to fire when handler returns#5721
danlapid merged 1 commit intomainfrom
dlapid/fix_jsrpc_return_event

Conversation

@danlapid
Copy link
Copy Markdown
Collaborator

Previously, the Return tracing event for JSRPC calls was emitted when the entire session completed (after all streams were consumed and capabilities released). This was incorrect - the Return event should mark when the handler returned a value, not when all data transfer finished.

Move setReturn() from JsRpcSessionCustomEvent::run() completion to EntrypointJsRpcTarget::call() completion. This ensures the Return event fires at the correct time in the request lifecycle.

Add tests that validate:

  • Return event occurs before Outcome event
  • Return event occurs at least 200ms after onset (handler work time)
  • Gap between Return and Outcome is at least 200ms (stream drain time)

@danlapid danlapid requested review from a team as code owners December 17, 2025 23:03
@danlapid danlapid requested review from fhanau and mar-cf December 17, 2025 23:03
@danlapid
Copy link
Copy Markdown
Collaborator Author

Yes, I know using timing for tests is unreliable.
But because of that annoying reason we have NO tests actually testing this behavior - that is unacceptable.
I ran this test with bazel test --runs_per_test=500 //src/workerd/api/tests:jsrpc-timing-test and it passed to make sure it doesn't flake.

Previously, the Return tracing event for JSRPC calls was emitted when
the entire session completed (after all streams were consumed and
capabilities released). This was incorrect - the Return event should
mark when the handler returned a value, not when all data transfer
finished.

Move setReturn() from JsRpcSessionCustomEvent::run() completion to
EntrypointJsRpcTarget::call() completion. This ensures the Return
event fires at the correct time in the request lifecycle.

Add tests that validate:
- Return event occurs before Outcome event
- Return event occurs at least 200ms after onset (handler work time)
- Gap between Return and Outcome is at least 200ms (stream drain time)
@danlapid danlapid force-pushed the dlapid/fix_jsrpc_return_event branch from a076a2f to f840511 Compare December 17, 2025 23:38
@danlapid danlapid merged commit f4e24b0 into main Dec 18, 2025
21 checks passed
@danlapid danlapid deleted the dlapid/fix_jsrpc_return_event branch December 18, 2025 15:27
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.

3 participants