Commit 7bc9734
authored
Abort :http streaming read when the consumer closes the channel (#98)
The :http backend's streaming request had no way to abort an in-flight
socket read when the consumer closes `stream_to`. Closing the channel
stopped the chunk-reader task but left the read task blocked in
`eof(io)`/`readbytes!(io)` on the socket, so a streaming request whose
consumer stops early (e.g. a Kubernetes watch stopped via `close(stream)`
after the awaited event arrives, or a timer firing) would hang until the
read-idle timeout instead of returning promptly.
Add an abort-on-close watcher task, mirroring the :downloads backend:
capture the connection `io`, and when `stream_to` closes, close `io` and
schedule an `InterruptException` on the read task. `close(io)` alone does
not wake an HTTP/2 body read parked on the flow-control timer
(`_wait_h2_body_progress!` -> `timedwait`), so the scheduled interrupt is
what reliably unblocks it (the same fallback :downloads uses for
non-interruptible downloads). The read task swallows the abort (channel
closed, or our InterruptException) and returns normally; a genuine
network error or read-idle timeout arrives while `stream_to` is still
open, so it still propagates. The interrupt surfaces to callers as
`InvocationException("request was interrupted")` via `exec`, which
`is_request_interrupted` already recognizes.
Affects both HTTP.jl 1.x and 2.x (shared :http code path). Validated
against a live Kubernetes watch on HTTP 1.11 and 2.5: consumer-initiated
stop now returns in ~2-3s instead of hanging.1 parent 3f9bf09 commit 7bc9734
1 file changed
Lines changed: 55 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
293 | 298 | | |
294 | | - | |
| 299 | + | |
295 | 300 | | |
296 | 301 | | |
| 302 | + | |
297 | 303 | | |
298 | 304 | | |
299 | 305 | | |
| |||
311 | 317 | | |
312 | 318 | | |
313 | 319 | | |
314 | | - | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
315 | 329 | | |
316 | 330 | | |
317 | 331 | | |
| |||
337 | 351 | | |
338 | 352 | | |
339 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
340 | 393 | | |
341 | 394 | | |
342 | 395 | | |
| |||
0 commit comments