From 7d90e5588a8c21dbc0a18f63e81af22486c73303 Mon Sep 17 00:00:00 2001 From: HBaghdadi1995 <34271143+HBaghdadi1995@users.noreply.github.com> Date: Wed, 6 Mar 2019 18:35:12 +0000 Subject: [PATCH 1/5] Add option to disable idle_timeout --- src/ConnectionPool.jl | 12 +++++++----- src/Servers.jl | 8 +++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/ConnectionPool.jl b/src/ConnectionPool.jl index f24efcfbc..9eb60f461 100644 --- a/src/ConnectionPool.jl +++ b/src/ConnectionPool.jl @@ -70,6 +70,7 @@ mutable struct Connection{T <: IO} peerport::UInt16 # debug only localport::UInt16 # debug only io::T + idle_timeout_enabled::Bool buffer::IOBuffer sequence::Int writecount::Int @@ -95,13 +96,13 @@ end Connection(host::AbstractString, port::AbstractString, pipeline_limit::Int, idle_timeout::Int, - require_ssl_verification::Bool, io::T) where T <: IO = + require_ssl_verification::Bool, io::T, idle_timeout_enabled = true) where T <: IO = Connection{T}(host, port, pipeline_limit, idle_timeout, require_ssl_verification, peerport(io), localport(io), - io, PipeBuffer(), - -1, + io, idle_timeout_enabled, + PipeBuffer(), -1, 0, false, Condition(), 0, false, Condition(), time()) @@ -123,7 +124,7 @@ getrawstream(t::Transaction) = t.c.io inactiveseconds(t::Transaction) = inactiveseconds(t.c) function inactiveseconds(c::Connection)::Float64 - if !c.readbusy && !c.writebusy + if !c.readbusy && !c.writebusy || !c.idle_timeout_enabled return 0.0 end return time() - c.timestamp @@ -456,7 +457,8 @@ function purge() if c.idle_timeout > 0 && !c.readbusy && !c.writebusy && - time() - c.timestamp > c.idle_timeout + time() - c.timestamp > c.idle_timeout && + c.idle_timeout_enabled close(c.io) ;@debug 1 "⌛️ Timeout: $c" end diff --git a/src/Servers.jl b/src/Servers.jl index 00833908d..162377d00 100644 --- a/src/Servers.jl +++ b/src/Servers.jl @@ -196,7 +196,8 @@ function listen(f, rate_limit::Union{Rational{Int}, Nothing}=nothing, reuse_limit::Int=nolimit, readtimeout::Int=60, - verbose::Bool=false) + verbose::Bool=false, + idle_timeout_enabled = true) inet = getinet(host, port) if server !== nothing @@ -222,7 +223,7 @@ function listen(f, s = Server(sslconfig, tcpserver, string(host), string(port)) return listenloop(f, s, tcpisvalid, connection_count, - reuse_limit, readtimeout, verbose) + reuse_limit, readtimeout, verbose, idle_timeout_enabled) end """" @@ -230,7 +231,7 @@ Main server loop. Accepts new tcp connections and spawns async tasks to handle them." """ function listenloop(f, server, tcpisvalid, connection_count, - reuse_limit, readtimeout, verbose) + reuse_limit, readtimeout, verbose, idle_timeout_enabled = true) count = 1 while isopen(server) try @@ -243,6 +244,7 @@ function listenloop(f, server, tcpisvalid, connection_count, connection_count[] += 1 conn = Connection(io) conn.host, conn.port = server.hostname, server.hostport + conn.idle_timeout_enabled = idle_timeout_enabled let io=io, count=count @async try verbose && @info "Accept ($count): $conn" From a30a41cee88dcd14e0c611f040c006ccd03816ab Mon Sep 17 00:00:00 2001 From: HBaghdadi1995 <34271143+HBaghdadi1995@users.noreply.github.com> Date: Wed, 6 Mar 2019 18:35:45 +0000 Subject: [PATCH 2/5] Websockets disable timeout --- src/WebSockets.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebSockets.jl b/src/WebSockets.jl index 6ce441551..857f84e77 100644 --- a/src/WebSockets.jl +++ b/src/WebSockets.jl @@ -117,7 +117,7 @@ function listen(f::Function, host::String="localhost", port::UInt16=UInt16(8081); binary=false, verbose=false) - HTTP.listen(host, port; verbose=verbose) do http + HTTP.listen(host, port; verbose=verbose, idle_timeout_enabled = false) do http upgrade(f, http; binary=binary) end end From 94aba6f95a9d459fdaa5b70871593f65b2ba88f5 Mon Sep 17 00:00:00 2001 From: HBaghdadi1995 <34271143+HBaghdadi1995@users.noreply.github.com> Date: Thu, 14 Mar 2019 13:14:31 +0000 Subject: [PATCH 3/5] Reverted hardcoded read_timeout --- src/HTTP.jl | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/HTTP.jl b/src/HTTP.jl index 035e67f29..e4c080f8a 100644 --- a/src/HTTP.jl +++ b/src/HTTP.jl @@ -610,9 +610,6 @@ function stack(;redirect=true, verbose=0, kw...) - # hard code readtimeout of 0 to disable timeout until #341 can be properly resolved - readtimeout = 0 - NoLayer = Union (redirect ? RedirectLayer : NoLayer){ From 4ff6b322dbaaf5e1656bd98e2d1af5a85360c87f Mon Sep 17 00:00:00 2001 From: HBaghdadi1995 <34271143+HBaghdadi1995@users.noreply.github.com> Date: Thu, 14 Mar 2019 13:16:11 +0000 Subject: [PATCH 4/5] Set readtimeout to 0 --- src/Servers.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Servers.jl b/src/Servers.jl index 162377d00..2531f132a 100644 --- a/src/Servers.jl +++ b/src/Servers.jl @@ -195,9 +195,9 @@ function listen(f, connection_count::Ref{Int}=Ref(0), rate_limit::Union{Rational{Int}, Nothing}=nothing, reuse_limit::Int=nolimit, - readtimeout::Int=60, verbose::Bool=false, idle_timeout_enabled = true) + readtimeout::Int=0, inet = getinet(host, port) if server !== nothing From 1d1d0efac60576b13ec120a26cc3164fc8bdfa86 Mon Sep 17 00:00:00 2001 From: HBaghdadi1995 <34271143+HBaghdadi1995@users.noreply.github.com> Date: Thu, 14 Mar 2019 13:16:37 +0000 Subject: [PATCH 5/5] Remove Idle_timeout enabled --- src/ConnectionPool.jl | 12 +++++------- src/Servers.jl | 8 +++----- src/WebSockets.jl | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/ConnectionPool.jl b/src/ConnectionPool.jl index 9eb60f461..f24efcfbc 100644 --- a/src/ConnectionPool.jl +++ b/src/ConnectionPool.jl @@ -70,7 +70,6 @@ mutable struct Connection{T <: IO} peerport::UInt16 # debug only localport::UInt16 # debug only io::T - idle_timeout_enabled::Bool buffer::IOBuffer sequence::Int writecount::Int @@ -96,13 +95,13 @@ end Connection(host::AbstractString, port::AbstractString, pipeline_limit::Int, idle_timeout::Int, - require_ssl_verification::Bool, io::T, idle_timeout_enabled = true) where T <: IO = + require_ssl_verification::Bool, io::T) where T <: IO = Connection{T}(host, port, pipeline_limit, idle_timeout, require_ssl_verification, peerport(io), localport(io), - io, idle_timeout_enabled, - PipeBuffer(), -1, + io, PipeBuffer(), + -1, 0, false, Condition(), 0, false, Condition(), time()) @@ -124,7 +123,7 @@ getrawstream(t::Transaction) = t.c.io inactiveseconds(t::Transaction) = inactiveseconds(t.c) function inactiveseconds(c::Connection)::Float64 - if !c.readbusy && !c.writebusy || !c.idle_timeout_enabled + if !c.readbusy && !c.writebusy return 0.0 end return time() - c.timestamp @@ -457,8 +456,7 @@ function purge() if c.idle_timeout > 0 && !c.readbusy && !c.writebusy && - time() - c.timestamp > c.idle_timeout && - c.idle_timeout_enabled + time() - c.timestamp > c.idle_timeout close(c.io) ;@debug 1 "⌛️ Timeout: $c" end diff --git a/src/Servers.jl b/src/Servers.jl index 2531f132a..c693b288f 100644 --- a/src/Servers.jl +++ b/src/Servers.jl @@ -195,9 +195,8 @@ function listen(f, connection_count::Ref{Int}=Ref(0), rate_limit::Union{Rational{Int}, Nothing}=nothing, reuse_limit::Int=nolimit, - verbose::Bool=false, - idle_timeout_enabled = true) readtimeout::Int=0, + verbose::Bool=false) inet = getinet(host, port) if server !== nothing @@ -223,7 +222,7 @@ function listen(f, s = Server(sslconfig, tcpserver, string(host), string(port)) return listenloop(f, s, tcpisvalid, connection_count, - reuse_limit, readtimeout, verbose, idle_timeout_enabled) + reuse_limit, readtimeout, verbose) end """" @@ -231,7 +230,7 @@ Main server loop. Accepts new tcp connections and spawns async tasks to handle them." """ function listenloop(f, server, tcpisvalid, connection_count, - reuse_limit, readtimeout, verbose, idle_timeout_enabled = true) + reuse_limit, readtimeout, verbose) count = 1 while isopen(server) try @@ -244,7 +243,6 @@ function listenloop(f, server, tcpisvalid, connection_count, connection_count[] += 1 conn = Connection(io) conn.host, conn.port = server.hostname, server.hostport - conn.idle_timeout_enabled = idle_timeout_enabled let io=io, count=count @async try verbose && @info "Accept ($count): $conn" diff --git a/src/WebSockets.jl b/src/WebSockets.jl index 857f84e77..6ce441551 100644 --- a/src/WebSockets.jl +++ b/src/WebSockets.jl @@ -117,7 +117,7 @@ function listen(f::Function, host::String="localhost", port::UInt16=UInt16(8081); binary=false, verbose=false) - HTTP.listen(host, port; verbose=verbose, idle_timeout_enabled = false) do http + HTTP.listen(host, port; verbose=verbose) do http upgrade(f, http; binary=binary) end end