Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
put cap of 1 second to NewPeerClient connect
Browse files Browse the repository at this point in the history
  • Loading branch information
miparnisari committed Feb 25, 2024
1 parent e7eabb0 commit f132176
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions gubernator.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ func (s *V1Instance) SetPeers(peerInfo []PeerInfo) {
})
if err != nil {
s.log.Error("error connecting to peer: %s", err)
return
}
}
regionPicker.Add(peer)
Expand All @@ -628,6 +629,7 @@ func (s *V1Instance) SetPeers(peerInfo []PeerInfo) {
})
if err != nil {
s.log.Error("error connecting to peer: %s", err)
return
}
}
localPicker.Add(peer)
Expand Down
8 changes: 6 additions & 2 deletions peer_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"sync"
"sync/atomic"
"time"

"github.com/mailgun/holster/v4/clock"
"github.com/mailgun/holster/v4/collections"
Expand Down Expand Up @@ -79,7 +80,7 @@ type PeerConfig struct {
TraceGRPC bool
}

// NewPeerClient establishes a connection to a peer in a blocking fashion.
// NewPeerClient tries to establish a connection to a peer in a blocking fashion with a 1 second timeout.
// If batching is enabled, it also starts a goroutine where batches will be processed.
func NewPeerClient(conf PeerConfig) (*PeerClient, error) {
peerClient := &PeerClient{
Expand All @@ -101,8 +102,11 @@ func NewPeerClient(conf PeerConfig) (*PeerClient, error) {
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}

ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()

var err error
peerClient.conn, err = grpc.Dial(conf.Info.GRPCAddress, opts...)
peerClient.conn, err = grpc.DialContext(ctx, conf.Info.GRPCAddress, opts...)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit f132176

Please sign in to comment.