diff --git a/src/curl.jl b/src/curl.jl index 371f1a9..06b92a5 100644 --- a/src/curl.jl +++ b/src/curl.jl @@ -215,15 +215,10 @@ function recv_data(easy::Curl.Easy, output::Channel{T}, max_recv_message_length: end function set_connect_timeout(easy::Curl.Easy, timeout::Real) - timeout >= 0 || + (0 ≤ timeout ≤ (typemax(Clong) ÷ 1000)) || throw(ArgumentError("timeout must be positive, got $timeout")) - if timeout ≤ typemax(Clong) ÷ 1000 - timeout_ms = round(Clong, timeout * 1000) - Curl.setopt(easy, CURLOPT_CONNECTTIMEOUT_MS, timeout_ms) - else - timeout = timeout ≤ typemax(Clong) ? round(Clong, timeout) : Clong(0) - Curl.setopt(easy, CURLOPT_CONNECTTIMEOUT, timeout) - end + timeout_ms = round(Clong, timeout * 1000) + Curl.setopt(easy, CURLOPT_CONNECTTIMEOUT_MS, timeout_ms) end # Prevent reuse of this handle diff --git a/src/grpc.jl b/src/grpc.jl index 7d940fe..ba28a02 100644 --- a/src/grpc.jl +++ b/src/grpc.jl @@ -90,8 +90,8 @@ Contains settings to control the behavior of gRPC requests. tls), or `:http2` (http2 upgrade) - `revocation`: whether to check for certificate recovation (default is true) - `request_timeout`: request timeout (seconds) -- `connect_timeout`: connect timeout (seconds) (default is 300 seconds, same - as setting this to 0) +- `connect_timeout`: connect timeout (seconds) (must be ≤ typemax(Clong)÷1000, + default is 300 seconds, same as setting this to 0) - `max_message_length`: maximum message length (default is 4MB) - `max_recv_message_length`: maximum message length to receive (default is `max_message_length`, same as setting this to 0) @@ -126,7 +126,8 @@ struct gRPCController <: ProtoRpcController enable_shared_locks::Bool = false, verbose::Bool = false ) - if maxage < 0 || keepalive < 0 || request_timeout < 0 || connect_timeout < 0 || + if maxage < 0 || keepalive < 0 || request_timeout < 0 || + connect_timeout < 0 || connect_timeout > (typemax(Clong) ÷ 1000) || max_message_length < 0 || max_recv_message_length < 0 || max_send_message_length < 0 throw(ArgumentError("Invalid gRPCController parameter")) end diff --git a/test/test_grpcerrors.jl b/test/test_grpcerrors.jl index 23ca88b..f8899a3 100644 --- a/test/test_grpcerrors.jl +++ b/test/test_grpcerrors.jl @@ -144,9 +144,13 @@ end function test_connect_timeout() timeout_server_endpoint = "http://10.255.255.1/" # a non routable IP - timeout_secs = 5 - client = GRPCErrorsBlockingClient(timeout_server_endpoint; verbose=false, connect_timeout=timeout_secs) + @testset "connect timeout" begin + @test_throws ArgumentError GRPCErrorsBlockingClient(timeout_server_endpoint; verbose=false, connect_timeout=typemax(Clong)) + @test_throws ArgumentError GRPCErrorsBlockingClient(timeout_server_endpoint; verbose=false, connect_timeout=-1) + + timeout_secs = 5 + client = GRPCErrorsBlockingClient(timeout_server_endpoint; verbose=false, connect_timeout=timeout_secs) data = GrpcerrorsClients.Data(; mode=1, param=0) t1 = time() try @@ -166,4 +170,4 @@ end function test_clients(server_endpoint::String) @info("testing blocking client") test_blocking_client(server_endpoint) -end \ No newline at end of file +end