retry context canceled request

This commit is contained in:
Chris Lu
2020-01-24 01:40:51 -08:00
parent 2f75264ec7
commit 107e8a56ea
2 changed files with 27 additions and 6 deletions

View File

@@ -64,7 +64,14 @@ func WithCachedGrpcClient(ctx context.Context, fn func(*grpc.ClientConn) error,
existingConnection, found := grpcClients[address]
if found {
grpcClientsLock.Unlock()
return fn(existingConnection)
err := fn(existingConnection)
if err != nil {
grpcClientsLock.Lock()
delete(grpcClients, address)
grpcClientsLock.Unlock()
existingConnection.Close()
}
return err
}
grpcConnection, err := GrpcDial(ctx, address, opts...)