Skip to content

Commit

Permalink
fix(pubsub): fix defer call in for loop
Browse files Browse the repository at this point in the history
Signed-off-by: Koichi Shiraishi <[email protected]>
  • Loading branch information
zchee committed Dec 5, 2024
1 parent 9fe6199 commit 4aea6cf
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pubsub/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,15 +1083,22 @@ func (t *Topic) initBundler() {
defer cancel()
}
bmsgs := bundle.([]*bundledMessage)
var fns []func()
if t.enableTracing {
for _, m := range bmsgs {
fns = make([]func(), len(bmsgs))
for i, m := range bmsgs {
m.batcherSpan.End()
m.createSpan.AddEvent(eventPublishStart, trace.WithAttributes(semconv.MessagingBatchMessageCount(len(bmsgs))))
defer m.createSpan.End()
defer m.createSpan.AddEvent(eventPublishEnd)
fns[i] = func() {
m.createSpan.AddEvent(eventPublishEnd)
m.createSpan.End()
}
}
}
t.publishMessageBundle(ctx, bmsgs)
for _, fn := range fns {
fn()
}
})
t.scheduler.DelayThreshold = t.PublishSettings.DelayThreshold
t.scheduler.BundleCountThreshold = t.PublishSettings.CountThreshold
Expand Down

0 comments on commit 4aea6cf

Please sign in to comment.