Skip to content

Commit bbcd132

Browse files
committed
Add timeout to connection.Connect()
If connection.Connect() gets stuck it will block infinitely, never reporting an error to the library's consumer. We have received reports of this happening even when a _valid_ address is passed in node-driver-registrar because of a race condition involving pod restarts. Specifically, there is an unlucky sequence of events when restarting both the CSI Driver and node-driver-registrar, wheere the node-driver-registar will attempt to Connect() to the CSI Driver, but will get stuck doing so on an old file descriptor from the previously running CSI Driver (and thus, get stuck infinitely). There is no mechanism to pass a connection timeout to Connect, so this commit adds a reasonbly long default timeout so these cases will eventually return an error rather than getting stuck infinitely. Signed-off-by: Connor Catlett <[email protected]>
1 parent 597d128 commit bbcd132

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

connection/connection.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func SetMaxGRPCLogLength(characterCount int) {
5454
// file or have format '<protocol>://', following gRPC name resolution mechanism at
5555
// https://github.com/grpc/grpc/blob/master/doc/naming.md.
5656
//
57-
// The function tries to connect indefinitely every second until it connects. The function automatically disables TLS
58-
// and adds interceptor for logging of all gRPC messages at level 5.
57+
// The function tries to connect for 30 seconds, and returns an error if no connection has been established at that point.
58+
// The function automatically disables TLS and adds interceptor for logging of all gRPC messages at level 5.
5959
//
6060
// For a connection to a Unix Domain socket, the behavior after
6161
// loosing the connection is configurable. The default is to
@@ -70,7 +70,7 @@ func SetMaxGRPCLogLength(characterCount int) {
7070
// For other connections, the default behavior from gRPC is used and
7171
// loss of connection is not detected reliably.
7272
func Connect(address string, metricsManager metrics.CSIMetricsManager, options ...Option) (*grpc.ClientConn, error) {
73-
return connect(address, metricsManager, []grpc.DialOption{}, options)
73+
return connect(address, metricsManager, []grpc.DialOption{grpc.WithTimeout(time.Second * 30)}, options)
7474
}
7575

7676
// Option is the type of all optional parameters for Connect.

0 commit comments

Comments
 (0)