Skip to content

Commit 5bbd39f

Browse files
Use buf+1 for peek to force server round trip
1 parent ca291b8 commit 5bbd39f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

x/mongo/driver/topology/pool.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,9 +888,15 @@ func peekConnectionAlive(conn *connection) (int, error) {
888888
return 0, err
889889
}
890890

891+
// Figre out how many bytes are already buffered.
892+
buffered := conn.br.Buffered()
893+
891894
// Peek(1) will fill the bufio.Reader’s buffer if needed,
892895
// but will NOT advance it.
893-
bytes, err := conn.br.Peek(1)
896+
//
897+
// Peek buffered+1 bytes, which will read exactly one new byte from the
898+
// socket.
899+
bytes, err := conn.br.Peek(buffered + 1)
894900
return len(bytes), err
895901
}
896902

0 commit comments

Comments
 (0)