Skip to content

Commit b45ff4c

Browse files
committed
try again
1 parent 7f0d9b5 commit b45ff4c

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/Connections.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ function IOExtras.closeread(c::Connection)
299299
c.readable = false
300300
@debugv 3 "✉️ Read done: $c"
301301
if c.clientconnection
302-
t = Threads.@spawn monitor_idle_connection(c)
302+
t = @async monitor_idle_connection(c)
303303
@isdefined(errormonitor) && errormonitor(t)
304304
end
305305
return

src/Exceptions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ end # @eval
2828
function try_with_timeout(f, timeout)
2929
ch = Channel(0)
3030
timer = Timer(tm -> close(ch, TimeoutError(timeout)), timeout)
31-
Threads.@spawn try
31+
@async try
3232
put!(ch, $f())
3333
catch e
3434
if !(e isa HTTPError)

src/clientlayers/ConnectionRequest.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Otherwise leave it open so that it can be reused.
5656
"""
5757
function connectionlayer(handler)
5858
return function connections(req; proxy=getproxy(req.url.scheme, req.url.host), socket_type::Type=TCPSocket, socket_type_tls::Type=SOCKET_TYPE_TLS[], readtimeout::Int=0, logerrors::Bool=false, kw...)
59-
local io, stream
59+
local io, stream, ct, sticky, tid
6060
if proxy !== nothing
6161
target_url = req.url
6262
url = URI(proxy)
@@ -77,6 +77,10 @@ function connectionlayer(handler)
7777
start_time = time()
7878
try
7979
io = newconnection(IOType, url.host, url.port; readtimeout=readtimeout, kw...)
80+
ct = current_task()
81+
sticky = ct.sticky
82+
ct.sticky = true
83+
tid = Threads.threadid()
8084
catch e
8185
if logerrors
8286
@error "HTTP.ConnectError" exception=(e, catch_backtrace()) method=req.method url=req.url context=req.context
@@ -139,10 +143,13 @@ function connectionlayer(handler)
139143
e isa HTTPError || throw(RequestError(req, e))
140144
rethrow(e)
141145
finally
146+
# restory stickiness
147+
ct.sticky = sticky
142148
releaseconnection(io, shouldreuse; kw...)
143149
if !shouldreuse
144150
@try Base.IOError close(io)
145151
end
152+
@assert Threads.threadid() == tid
146153
end
147154
end
148155
end

src/clientlayers/StreamRequest.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ function streamlayer(stream::Stream; iofunction=nothing, decompress::Union{Nothi
3333
try
3434
@sync begin
3535
if iofunction === nothing
36-
Threads.@spawn try
36+
@async try
3737
writebody(stream, req)
3838
@debugv 2 "client closewrite"
3939
closewrite(stream)
4040
finally
4141
req.context[:write_duration_ms] = get(req.context, :write_duration_ms, 0.0) + ((time() - write_start) * 1000)
4242
end
4343
read_start = time()
44-
Threads.@spawn try
44+
@async try
4545
@debugv 2 "client startread"
4646
startread(stream)
4747
if isaborted(stream)

0 commit comments

Comments
 (0)