Skip to content

Commit 0308408

Browse files
sentrivanaclaude
andcommitted
fix: Don't finish span prematurely on read(0)
Drop the `not rv` check from the read() wrapper's span-finishing condition. read(0) legitimately returns b"" without consuming the body, which would falsely trigger span completion. The fp and closed checks are sufficient to detect when the body is fully consumed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bc404b6 commit 0308408

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

sentry_sdk/integrations/stdlib.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,13 @@ def read(self: "HTTPResponse", *args: "Any", **kwargs: "Any") -> "Any":
214214
if span is None:
215215
return real_read(self, *args, **kwargs)
216216

217-
rv = None
218217
try:
219-
rv = real_read(self, *args, **kwargs)
220-
return rv
218+
return real_read(self, *args, **kwargs)
221219
finally:
222220
# read() might be called multiple times to consume a single body,
223221
# so we can't just end the span when read() is done. Instead,
224222
# try to figure out whether the response body has been fully read.
225-
if self.fp is None or self.closed or not rv:
223+
if self.fp is None or self.closed:
226224
self._sentrysdk_span = None # type: ignore[attr-defined]
227225
_finish_span(span)
228226

0 commit comments

Comments
 (0)