-
Type: Improvement
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: CMAP, Connections
-
None
Context
Currently the Go driver never attempts to detect connections that were closed by the other side when checking out connections. As a result, it's possible to return a connection that's been closed by the other side where any read or write operations will immediately fail. Instead, we should check if the connection has been closed when checking out a connection.
Definition of done
- Check if a connection has been closed when checking out the connection. If it has, discard it and try to return another connection.
Pitfalls
Checking if a connection has been closed by the other side isn't as straightforward as calling an IsClosed method on the connection. These are some possible approaches:
- Make a non-blocking read request for the connection. If an error is returned, the connection is closed.
- That depends on the ability to call a non-blocking read, which may or may not be practical in Go.
- Call conn.Read with a very short read deadline. If an error is returned, the connection is closed.
- We need to make sure conn.Read returns before using the connection to run an operation. Otherwise, there will be concurrent read and write requests, which will lead to undefined behavior.
- Investigate the APIs available by type-asserting the conn to a *TCPConn, possibly using the underlying file descriptor to figure out its state.
- It's not clear if that's possible.
- is cloned by
-
GODRIVER-3363 [v2.0] Detect and discard closed connections during check-out
- Closed