Skip to content

Commit

Permalink
fix timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanut Lertwarachai authored and Tanut Lertwarachai committed Feb 2, 2025
1 parent 7a5bd62 commit 05faf2f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions relayer/band/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ func NewClient(queryClient QueryClient, log *zap.Logger, bandChainCfg *Config) C
// Init initializes the BandChain client by connecting to the chain and starting
// periodic liveliness checks.
func (c *client) Init(ctx context.Context) error {
timeout := uint(c.Config.Timeout)
if err := c.connect(timeout, true); err != nil {
if err := c.connect(true); err != nil {
c.Log.Error("Failed to connect to BandChain", zap.Error(err))
return err
}

go c.startLivelinessCheck(ctx, timeout, c.Config.LivelinessCheckingInterval)
go c.startLivelinessCheck(ctx)
return nil
}

// connect connects to the BandChain using the provided RPC endpoints.
func (c *client) connect(timeout uint, onStartup bool) error {
func (c *client) connect(onStartup bool) error {
timeout := uint(c.Config.Timeout)
for _, rpcEndpoint := range c.Config.RpcEndpoints {
// Create a new HTTP client for the specified node URI
client, err := httpclient.NewWithTimeout(rpcEndpoint, "/websocket", timeout)
Expand Down Expand Up @@ -101,8 +101,8 @@ func (c *client) connect(timeout uint, onStartup bool) error {
}

// startLivelinessCheck starts the liveliness check for the BandChain.
func (c *client) startLivelinessCheck(ctx context.Context, timeout uint, interval time.Duration) {
ticker := time.NewTicker(interval)
func (c *client) startLivelinessCheck(ctx context.Context) {
ticker := time.NewTicker(c.Config.LivelinessCheckingInterval)
for {
select {
case <-ctx.Done():
Expand All @@ -118,7 +118,7 @@ func (c *client) startLivelinessCheck(ctx context.Context, timeout uint, interva
zap.String("rpcEndpoint", c.Context.NodeURI),
zap.Error(err),
)
if err := c.connect(timeout, false); err != nil {
if err := c.connect(false); err != nil {
c.Log.Error("Liveliness check: unable to reconnect to any endpoints", zap.Error(err))
}
}
Expand Down

0 comments on commit 05faf2f

Please sign in to comment.