Skip to content

Commit f9bdcf0

Browse files
committed
[CWS] make sure events are sent in order, even after retry
1 parent e22b96c commit f9bdcf0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/security/module/server.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func (a *APIServer) dequeue(now time.Time, cb func(msg *pendingMsg) bool) {
223223
a.queueLock.Lock()
224224
defer a.queueLock.Unlock()
225225

226-
a.queue = slices.DeleteFunc(a.queue, func(msg *pendingMsg) bool {
226+
a.queue = slicesDeleteUntilFalse(a.queue, func(msg *pendingMsg) bool {
227227
if msg.sendAfter.After(now) {
228228
return false
229229
}
@@ -245,6 +245,17 @@ func (a *APIServer) dequeue(now time.Time, cb func(msg *pendingMsg) bool) {
245245
})
246246
}
247247

248+
// slicesDeleteUntilFalse deletes elements from the slice until the function f returns false.
249+
func slicesDeleteUntilFalse(s []*pendingMsg, f func(*pendingMsg) bool) []*pendingMsg {
250+
for i, v := range s {
251+
if !f(v) {
252+
return s[i:]
253+
}
254+
}
255+
256+
return nil
257+
}
258+
248259
func (a *APIServer) updateMsgService(msg *api.SecurityEventMessage) {
249260
// look for the service tag if we don't have one yet
250261
if len(msg.Service) == 0 {

0 commit comments

Comments
 (0)