Skip to content

Commit 0270461

Browse files
krynjuclaude
andauthored
fix(client): abort-on-close watcher busy-spins while events are pending (#101)
The watcher added in #98 waited with `wait(stream_to); yield()` in a loop. `wait(::Channel)` returns as soon as data is *available*, so whenever an event sits in the channel before the consumer takes it, the loop spins hot — measured at 100% of a core in system time on a k8s watch stream. Poll `isopen` with a 250ms sleep instead; the watcher only exists to abort the read when the consumer walks away, so the added abort latency is irrelevant. Bumps to 0.2.6. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 39c46f6 commit 0270461

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ keywords = ["Swagger", "OpenAPI", "REST"]
44
license = "MIT"
55
desc = "OpenAPI server and client helper for Julia"
66
authors = ["JuliaHub Inc."]
7-
version = "0.2.5"
7+
version = "0.2.6"
88

99
[deps]
1010
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/client/httplibs/juliaweb_http.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,14 @@ function _http_streaming_request(ctx, method, url, headers, body, timeout, bytes
373373
# read-idle timeout. Mirrors the `:downloads` backend, which interrupts
374374
# its download task on channel close.
375375
try
376+
# Block until the consumer closes the channel. Do NOT use
377+
# `wait(stream_to)`: it returns as soon as data is AVAILABLE, so
378+
# while an event sits in the channel not yet consumed, a
379+
# wait+yield loop degenerates into a hot spin that burns a full
380+
# core in scheduler/syscall overhead. Poll `isopen` instead;
381+
# 250ms of extra abort latency is irrelevant here.
376382
while isopen(stream_to)
377-
wait(stream_to)
378-
yield()
383+
sleep(0.25)
379384
end
380385
catch ex
381386
isa(ex, InvalidStateException) || rethrow(ex)

0 commit comments

Comments
 (0)