Skip to content

Commit 456a1fd

Browse files
committed
Delete method connection.isAlive() that are no longer in use.
1 parent 8757af0 commit 456a1fd

File tree

1 file changed

+0
-43
lines changed

1 file changed

+0
-43
lines changed

x/mongo/driver/topology/connection.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"fmt"
1515
"io"
1616
"net"
17-
"os"
1817
"strings"
1918
"sync"
2019
"sync/atomic"
@@ -526,48 +525,6 @@ func (c *connection) closed() bool {
526525
return atomic.LoadInt64(&c.state) == connDisconnected
527526
}
528527

529-
// isAlive returns true if the connection is alive and ready to be used for an
530-
// operation.
531-
//
532-
// Note that the liveness check can be slow (at least 1ms), so isAlive only
533-
// checks the liveness of the connection if it's been idle for at least 10
534-
// seconds. For frequently in-use connections, a network error during an
535-
// operation will be the first indication of a dead connection.
536-
func (c *connection) isAlive() bool {
537-
if c.nc == nil {
538-
return false
539-
}
540-
541-
// If the connection has been idle for less than 10 seconds, skip the
542-
// liveness check.
543-
//
544-
// The 10-seconds idle bypass is based on the liveness check implementation
545-
// in the Python Driver. That implementation uses 1 second as the idle
546-
// threshold, but we chose to be more conservative in the Go Driver because
547-
// this is new behavior with unknown side-effects. See
548-
// https://github.com/mongodb/mongo-python-driver/blob/e6b95f65953e01e435004af069a6976473eaf841/pymongo/synchronous/pool.py#L983-L985
549-
idleStart, ok := c.idleStart.Load().(time.Time)
550-
if !ok || idleStart.Add(10*time.Second).After(time.Now()) {
551-
return true
552-
}
553-
554-
// Set a 1ms read deadline and attempt to read 1 byte from the connection.
555-
// Expect it to block for 1ms then return a deadline exceeded error. If it
556-
// returns any other error, the connection is not usable, so return false.
557-
// If it doesn't return an error and actually reads data, the connection is
558-
// also not usable, so return false.
559-
//
560-
// Note that we don't need to un-set the read deadline because the "read"
561-
// and "write" methods always reset the deadlines.
562-
err := c.nc.SetReadDeadline(time.Now().Add(1 * time.Millisecond))
563-
if err != nil {
564-
return false
565-
}
566-
var b [1]byte
567-
_, err = c.nc.Read(b[:])
568-
return errors.Is(err, os.ErrDeadlineExceeded)
569-
}
570-
571528
func (c *connection) idleTimeoutExpired() bool {
572529
if c.idleTimeout == 0 {
573530
return false

0 commit comments

Comments
 (0)