Skip to content

Commit

Permalink
Fix set_default_connection_limit not being respected (#1053)
Browse files Browse the repository at this point in the history
* Fix set_default_connection_limit not being respected

With all the default global connection pool shuffling that has
happened, we missed making sure `set_default_connection_limit!`
was still being respected. It was updating the global connection
limit ref, but the global pools were still stuck with whatever their
values were when first initialized.

This PR reinitializes the global connection pools when the default
connection pool limit is changed.

* Update test/client.jl

Co-authored-by: Nick Robinson <[email protected]>

---------

Co-authored-by: Nick Robinson <[email protected]>
  • Loading branch information
quinnj and nickrobinson251 authored May 19, 2023
1 parent d8392a2 commit 1070b46
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Connections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ function __init__()
return
end

set_default_connection_limit!(n) = default_connection_limit[] = n
function set_default_connection_limit!(n)
default_connection_limit[] = n
# reinitialize the global connection pools
TCP_POOL[] = CPool{Sockets.TCPSocket}(n)
MBEDTLS_POOL[] = CPool{MbedTLS.SSLContext}(n)
OPENSSL_POOL[] = CPool{OpenSSL.SSLStream}(n)
return
end

"""
Connection
Expand Down
7 changes: 6 additions & 1 deletion test/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ using URIs
using InteractiveUtils: @which

# test we can adjust default_connection_limit
HTTP.set_default_connection_limit!(12)
for x in (10, 12)
HTTP.set_default_connection_limit!(x)
@test HTTP.Connections.TCP_POOL[].max == x
@test HTTP.Connections.MBEDTLS_POOL[].max == x
@test HTTP.Connections.OPENSSL_POOL[].max == x
end

@testset "@client macro" begin
@eval module MyClient
Expand Down

0 comments on commit 1070b46

Please sign in to comment.