Skip to content

Commit

Permalink
reset the signal channel after disconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
MStreet3 committed Dec 13, 2024
1 parent d86506b commit 1d46cf2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/services/gateway/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand All @@ -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():
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1d46cf2

Please sign in to comment.