mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-21 23:20:24 +00:00
simplify closing a connection
get the connection from the map instead of cycling all the open connections
This commit is contained in:
parent
871e2ccbbf
commit
62224debd2
1 changed files with 7 additions and 10 deletions
|
@ -220,13 +220,10 @@ func CloseActiveConnection(connectionID string) bool {
|
|||
result := false
|
||||
mutex.RLock()
|
||||
defer mutex.RUnlock()
|
||||
for _, c := range openConnections {
|
||||
if c.ID == connectionID {
|
||||
err := c.close()
|
||||
c.Log(logger.LevelDebug, logSender, "close connection requested, close err: %v", err)
|
||||
result = true
|
||||
break
|
||||
}
|
||||
if c, ok := openConnections[connectionID]; ok {
|
||||
err := c.close()
|
||||
c.Log(logger.LevelDebug, logSender, "close connection requested, close err: %v", err)
|
||||
result = true
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
@ -324,10 +321,10 @@ func removeConnection(c Connection) {
|
|||
delete(openConnections, c.ID)
|
||||
metrics.UpdateActiveConnectionsSize(len(openConnections))
|
||||
// we have finished to send data here and most of the time the underlying network connection
|
||||
// is already closed. Sometime a client can still be reading, the last sended data, from the
|
||||
// connection so we set a deadline instead of directly closing the network connection.
|
||||
// is already closed. Sometime a client can still be reading the last sended data, so we set
|
||||
// a deadline instead of directly closing the network connection.
|
||||
// Setting a deadline on an already closed connection has no effect.
|
||||
// We only need to ensure that a connection will not remain undefinitely open and so the
|
||||
// We only need to ensure that a connection will not remain indefinitely open and so the
|
||||
// underlying file descriptor is not released.
|
||||
// This should protect us against buggy clients and edge cases.
|
||||
c.netConn.SetDeadline(time.Now().Add(2 * time.Minute))
|
||||
|
|
Loading…
Reference in a new issue