all: Send Close BEP msg on intentional disconnect (#5440)
This avoids waiting until next ping and timeout until the connection is actually closed both by notifying the peer of the disconnect and by immediately closing the local end of the connection after that. As a nice side effect, info level logging about dropped connections now have the actual reason in it, not a generic timeout error which looks like a real problem with the connection.
This commit is contained in:
@@ -9,7 +9,6 @@ package connections
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/url"
|
||||
"time"
|
||||
@@ -23,7 +22,6 @@ import (
|
||||
// that can be closed and has some metadata.
|
||||
type Connection interface {
|
||||
protocol.Connection
|
||||
io.Closer
|
||||
Type() string
|
||||
Transport() string
|
||||
RemoteAddr() net.Addr
|
||||
@@ -39,6 +37,11 @@ type completeConn struct {
|
||||
protocol.Connection
|
||||
}
|
||||
|
||||
func (c completeConn) Close(err error) {
|
||||
c.Connection.Close(err)
|
||||
c.internalConn.Close()
|
||||
}
|
||||
|
||||
// internalConn is the raw TLS connection plus some metadata on where it
|
||||
// came from (type, priority).
|
||||
type internalConn struct {
|
||||
@@ -82,6 +85,14 @@ func (t connType) Transport() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (c internalConn) Close() {
|
||||
// *tls.Conn.Close() does more than it says on the tin. Specifically, it
|
||||
// sends a TLS alert message, which might block forever if the
|
||||
// connection is dead and we don't have a deadline set.
|
||||
c.SetWriteDeadline(time.Now().Add(250 * time.Millisecond))
|
||||
c.Conn.Close()
|
||||
}
|
||||
|
||||
func (c internalConn) Type() string {
|
||||
return c.connType.String()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user