Skip to content

Implement true streaming responses - #12

Merged
dholth merged 9 commits into
mainfrom
11-streaming
Apr 26, 2026
Merged

dholth merged 9 commits into
mainfrom
11-streaming

Conversation

@dholth

@dholth dholth commented Apr 26, 2026

Copy link
Copy Markdown
Owner

Client is able to get headers, wait, get a line of the response, wait, and get another line of response.

Fix #11

dholth added 3 commits April 25, 2026 21:37
The core bug was that async_stream.signal_end_of_stream() was never called,
causing aread() and async iteration to hang forever waiting for more data.

The fix restores proper streaming semantics:
- In the streaming path, race headers_ready event against the raw completion
  future (not a wrapped coroutine, to avoid cancellation orphaning the future)
- When headers arrive first: return the response immediately; _finish_streaming
  runs in the background and signals end-of-stream when the transfer completes
- When transfer completes first (small/fast responses): signal end-of-stream
  inline before returning
- _finish_streaming also queues any pycurl errors into the stream so consumers
  see RemoteProtocolError instead of hanging

Result: 1000 parallel requests now complete in ~0.64s vs niquests ~0.71s.
- Skip redundant socket registration remove/add cycles when mode hasn't changed
- Update test_curl.py tests to work with non-blocking perform() API
- perform() now returns PerformHandle immediately instead of being awaitable
@dholth
dholth merged commit 518d098 into main Apr 26, 2026
4 of 5 checks passed
@dholth
dholth deleted the 11-streaming branch April 26, 2026 01:56

This branch had an error being deployed

1 failed deployment
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.

Support returning earlier from AsyncCurl.perform()

1 participant