From 1d46cf2442e3653eb4f77410424eecfe03029e73 Mon Sep 17 00:00:00 2001 From: Michael Street <5597260+MStreet3@users.noreply.github.com> Date: Fri, 13 Dec 2024 11:25:05 -0500 Subject: [PATCH] reset the signal channel after disconnecting --- core/services/gateway/connector/connector.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/services/gateway/connector/connector.go b/core/services/gateway/connector/connector.go index 5e06e96f02c..fcecc0c7c19 100644 --- a/core/services/gateway/connector/connector.go +++ b/core/services/gateway/connector/connector.go @@ -79,8 +79,6 @@ func (c *gatewayConnector) HealthReport() map[string]error { func (c *gatewayConnector) Name() string { return c.lggr.Name() } type gatewayState struct { - // mu controls access to the signal channel - mu sync.Mutex // signal channel is closed once the gateway is connected signalCh chan struct{} @@ -90,10 +88,12 @@ type gatewayState struct { wsClient network.WebSocketClient } +// A gatewayState is connected when the signal channel is closed func (gs *gatewayState) signal() { close(gs.signalCh) } +// awaitConn blocks until the gateway is connected or the context is done func (gs *gatewayState) awaitConn(ctx context.Context) error { select { case <-ctx.Done(): @@ -268,15 +268,17 @@ 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() <-closeCh c.lggr.Infow("connection closed", "url", gatewayState.url) + // reset backoff redialBackoff = utils.NewRedialBackoff() + + // reset signal channel + gatewayState.signalCh = make(chan struct{}) } select { case <-c.shutdownCh: