Skip to content

Commit

Permalink
unlock the eventMsg mu before removing it
Browse files Browse the repository at this point in the history
Signed-off-by: Chetan Banavikalmutt <[email protected]>
  • Loading branch information
chetan-rns committed Nov 26, 2024
1 parent 1f9447c commit 86c55bb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,15 @@ func (ew *EventWriter) sendEvent(resID string) {
return
}

isACKRemoved := false

eventMsg.mu.Lock()
defer eventMsg.mu.Unlock()
defer func() {
// Check if the mu is already unlocked while removing the ACK.
if !isACKRemoved {
eventMsg.mu.Unlock()
}
}()

logCtx := ew.log.WithFields(logrus.Fields{
"resource_id": resID,
Expand Down Expand Up @@ -424,7 +431,9 @@ func (ew *EventWriter) sendEvent(resID string) {

// We don't have to wait for an ACK if the current event is ACK. So, remove it from the EventWriter.
if Target(eventMsg.event) == TargetEventAck {
eventMsg.mu.Unlock()
ew.Remove(eventMsg.event)
logCtx.Trace("ACK is removed from the event writer")
isACKRemoved = true
}
}

0 comments on commit 86c55bb

Please sign in to comment.