Skip to content

Commit

Permalink
ConnectionPool: monitor idle connections
Browse files Browse the repository at this point in the history
When a connection is returned to the (read) pool,
add a monitor to it for receiving unexpected data (or EOF),
and kill / close the Connection object if any activity occurs
before the next write (when it should have simply been waiting idle in the pool)

per JuliaLang/MbedTLS.jl#145 (comment)

closes #214
closes #199
closes #220
closes JuliaWeb/GitHub.jl#106
  • Loading branch information
samoconnor authored and vtjnash committed Apr 17, 2018
1 parent 597c0c7 commit 5ab8a3f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/ConnectionPool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,20 @@ function IOExtras.closeread(t::Transaction)
notify(poolcondition)

@ensure !isreadable(t)

# (re)start a watcher for idle connections in the pool
# short-circuit if it is already dead or has already started to be reused
if isopen(t.c) && !t.c.writebusy && (t.c.writecount <= t.sequence + 1) # && !isreadable(t)
@schedule begin
if !eof(t.c.io) && # wait to see if receive any more data
!t.c.readbusy && # and aren't actively expecting to receive data
!t.c.writebusy && (t.c.writecount <= t.sequence + 1) # nor have returned from startwrite and/or called closewrite again
# other end must be in an invalid state, or terminated the connection:
# drop our end from the pool also
close(t.c)
end
end
end
return
end

Expand Down

0 comments on commit 5ab8a3f

Please sign in to comment.