Emscripten/Pyodide fetch transport crashes on responses with a null body (e.g. 204 No Content) #3787
Unanswered
qte77
asked this question in
Potential Issue
Replies: 1 comment
|
I verified this against both repositories. The null-body diagnosis is correct there. I submitted a focused fix to the branch that actually ships the transport, with sync and async browser regressions against a real 204 response: The shared adapter now falls back to |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Bug
JavascriptFetchTransport.handle_request/AsyncJavascriptFetchTransport.handle_async_request(httpx/_transports/jsfetch.py, present in the 0.28.1 tag andmaster) both route through_js_response_to_python(around line 171-188), which unconditionally does:Any response whose JS-side
bodyisnull-- a 204 No Content is the clearest real-world case, but this would apply to any response the browser/runtime's fetch layer represents with a null body -- crashes with:instead of returning a valid
httpx.Responsewith an empty body.Environment
hoodmane/httpxtagpyodide_release_5, which carries the identical unguarded line -- filing here since that fork and this repo both have Issues disabled, and this looked like the closest fit among the Discussion categories).Expected
_js_response_to_pythonreturns anhttpx.Responsewith an empty body (e.g.httpx.Response(status_code, headers=..., stream=httpx.ByteStream(b""))) when the underlying JS response has no readable body stream, instead of assuming.bodyis always stream-shaped.Suggested fix
Guard the body-stream access, e.g. duck-type on
hasattr(body, "getReader")(safer than aJsNulltype check, which is more version-fragile) before calling.getReader(), and construct an empty-body response on the fallback path. Both the sync and async call sites resolve_js_response_to_pythonvia a bare module-global lookup, so a single fix at that function covers both.Happy to provide a minimal repro script if useful -- this was found via a real production workload hitting a real 204 response, not synthetically constructed.
All reactions