Skip to content

Commit cc94df3

Browse files
committed
Move callback execution into separate goroutine
stops semaphore blocking on callback execution to complete
1 parent c717835 commit cc94df3

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

pkg/chipingress/batch/client.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func (b *Client) sendBatch(ctx context.Context, messages []*messageWithCallback)
128128
go func() {
129129
defer func() { <-b.maxConcurrentSends }()
130130

131+
// this is specifically to prevent long running network calls
131132
ctxTimeout, cancel := context.WithTimeout(ctx, b.maxPublishTimeout)
132133
defer cancel()
133134

@@ -141,12 +142,18 @@ func (b *Client) sendBatch(ctx context.Context, messages []*messageWithCallback)
141142
b.log.Errorw("failed to publish batch", "error", err)
142143
}
143144

144-
// Invoke callbacks for all messages in the batch
145-
for _, msg := range messages {
146-
if msg.callback != nil {
147-
msg.callback(err)
145+
go func() {
146+
for _, msg := range messages {
147+
select {
148+
case <-ctx.Done():
149+
return
150+
default:
151+
if msg.callback != nil {
152+
msg.callback(err)
153+
}
154+
}
148155
}
149-
}
156+
}()
150157
}()
151158
}
152159

0 commit comments

Comments
 (0)