diff --git a/core/services/gateway/connector/connector.go b/core/services/gateway/connector/connector.go index 0bdf85c6801..5e06e96f02c 100644 --- a/core/services/gateway/connector/connector.go +++ b/core/services/gateway/connector/connector.go @@ -91,12 +91,7 @@ type gatewayState struct { } func (gs *gatewayState) signal() { - gs.mu.Lock() - defer gs.mu.Unlock() - - ch := make(chan struct{}) - close(ch) - gs.signalCh = ch + close(gs.signalCh) } func (gs *gatewayState) awaitConn(ctx context.Context) error { @@ -104,10 +99,6 @@ func (gs *gatewayState) awaitConn(ctx context.Context) error { case <-ctx.Done(): return fmt.Errorf("await connection failed: %w", ctx.Err()) case <-gs.signalCh: - gs.mu.Lock() - defer gs.mu.Unlock() - - gs.signalCh = nil return nil } } @@ -153,6 +144,7 @@ func NewGatewayConnector(config *ConnectorConfig, signer Signer, clock clockwork config: gw, url: parsedURL, wsClient: network.NewWebSocketClient(config.WsClientConfig, connector, lggr), + signalCh: make(chan struct{}), } gateways[gw.Id] = gateway urlToId[gw.URL] = gw.Id @@ -276,6 +268,8 @@ func (c *gatewayConnector) reconnectLoop(gatewayState *gatewayState) { if err != nil { c.lggr.Errorw("connection error", "url", gatewayState.url, "err", err) } else { + c.lggr.Infow("waiting", "url", gatewayState.url) + <-time.After(5 * time.Second) c.lggr.Infow("connected successfully", "url", gatewayState.url) closeCh := gatewayState.conn.Reset(conn) gatewayState.signal()