Skip to content

Commit bb90158

Browse files
authored
fix: close redis proxy connection ID tracker on goroutine end (#520)
Signed-off-by: Jonathan West <[email protected]>
1 parent ee8c815 commit bb90158

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

principal/event.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,11 @@ func (s *Server) processRedisEventResponse(ctx context.Context, logCtx *logrus.E
377377
// PushFromSubscribe is asynchronous, so we can't use event id tracker to find the corresponding channel.
378378
// - We instead use connection id, which maps directly to the connection from Argo CD
379379
trAgent, evChan := s.redisProxy.ConnectionIDTracker.Tracked(resReq.ConnectionUUID)
380+
if evChan == nil {
381+
logCtx.Debug("connection UUID is no longer in connectionIDTracker, likely the principal connection has closed")
382+
return nil
383+
}
384+
380385
if trAgent != agentName {
381386
err := fmt.Errorf("agent mismap between event and tracking for PushFromSubscribe: '%s' '%s' '%s'", trAgent, agentName, resReq.ConnectionUUID)
382387
return err

principal/redisproxy/redisproxy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@ func (rp *RedisProxy) handleAgentSubscribe(connState *connectionState, channelNa
458458
// Forward all events from 'subscriptionChannel' to 'connectionUUIDEventsChannel'
459459
go func() {
460460
defer close(connState.connectionUUIDEventsChannel)
461+
defer func() {
462+
if err := rp.ConnectionIDTracker.StopTracking(connState.connUUID); err != nil {
463+
logCtx.WithError(err).Error("connection ID tracker reported an unexpected error. At this stage of the goroutine lifecycle, the resource should still necessarily be tracked.")
464+
}
465+
}()
461466

462467
for {
463468
select {

0 commit comments

Comments
 (0)