Skip to content

fix(core): End node:http client spans when the response is destroyed - #25503

Merged
isaacs merged 3 commits into
getsentry:developfrom
4ktLuffy:fix/node-http-client-span-on-response-destroy
Oct 27, 2026
Merged

isaacs merged 3 commits into
getsentry:developfrom
4ktLuffy:fix/node-http-client-span-on-response-destroy

Conversation

@4ktLuffy

Copy link
Copy Markdown
Contributor

When the caller destroys an http.get() response mid-body with res.destroy() (no error), the http.client span is never ended, so it is never sent. The response emits only close, not end or error, and the request close fallback is removed once the response arrives.

This adds a response close listener that ends the span. Following #25260, a destroy by the caller is not treated as a failure: the span keeps the status of the response (ok for a 200, error for a 404). res.destroy(err) and a server closing the connection mid-body still set an error status, because they emit error before close. After a normal end or an error, the new listener is a no-op.

Tests: caller destroy (200 and 404), caller destroy with an error, and a new server-abort case. The caller-destroy test times out without the fix. All 121 http tests pass. Reproduced on @sentry/node 11.8.0.

Closes #25469

@github-actions github-actions Bot added the external PR from an external contributor label Oct 19, 2026
@Lms24
Lms24 requested review from andreiborza and isaacs October 19, 2026 08:18

@s1gr1d s1gr1d left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution, I have some comments on it.

btw, also linking this PR for reference: #25260

Comment thread packages/core/src/integrations/http/client-subscriptions.ts Outdated
Comment thread packages/core/src/integrations/http/client-subscriptions.ts Outdated
Comment thread packages/core/src/integrations/http/client-subscriptions.ts Outdated
@4ktLuffy

Copy link
Copy Markdown
Contributor Author

Thanks, you were right. I reproduced it: with no error listener, a reset only emits close with errored set, and the span ended as ok. Pushed the fix:

  • close now calls finishWithResponse(response.errored), and destroyedByCaller is gone.
  • Also removed the aborted check, since Node sets aborted on a plain res.destroy() too.
  • Added errored to HttpIncomingMessage for the type check.
  • Tests now use the real errorMonitor (the old default added an error listener and hid the bug), plus a new test for a reset with no listener.

@github-actions

Copy link
Copy Markdown
Contributor

👋 @isaacs, @andreiborza — Please review this PR when you get a chance!

@isaacs
isaacs enabled auto-merge (squash) October 27, 2026 21:31
@isaacs
isaacs merged commit f8b8d40 into getsentry:develop Oct 27, 2026
661 of 664 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

node:http client span never ends when the response is destroyed without an error (res.destroy())

3 participants