ensure entry is registered before timeout is armed.

In the case of a zero timeout, the AfterFunc would attempt to deregister an unregistered entry.
Then a zombie entry would be added that would never be deregistered.
This commit is contained in:
Jay
2026-08-09 19:10:41 -04:00
parent de1ec56c40
commit 9672ca14c6
+7 -4
View File
@@ -99,6 +99,12 @@ func (p *EventPublisher) Publish(eventID string, eventJSON []byte, timeout time.
result: make(chan publishResult, 1),
}
p.mu.Lock()
p.pending[eventID] = entry
connected := p.envoy.IsConnected()
// use timeout if positive and nonzero
if timeout > time.Duration(0) {
entry.timer = time.AfterFunc(timeout, func() {
p.mu.Lock()
p.deregister(eventID)
@@ -107,10 +113,7 @@ func (p *EventPublisher) Publish(eventID string, eventJSON []byte, timeout time.
PublishTimeout{EventID: eventID, At: time.Now()})
p.deliver(entry, publishResult{err: errors.New("publish timeout")})
})
p.mu.Lock()
p.pending[eventID] = entry
connected := p.envoy.IsConnected()
}
p.mu.Unlock()
if connected {