diff --git a/eventbus/mysql/eventbus.go b/eventbus/mysql/eventbus.go index 7973b59fa7a5752c1f6a7186e77d522ad11b19b5..6fe3a5f32864a6a6227bf4c9bd8f24345fb09fbf 100644 --- a/eventbus/mysql/eventbus.go +++ b/eventbus/mysql/eventbus.go @@ -370,6 +370,7 @@ func (e *EventBus) getRetryEvents(db *gorm.DB, service *ServicePO) ([]*EventPO, if info.RetryTime.Before(now) { retryIDs = append(retryIDs, info.ID) } else { + // 保留未到重试时间的事件 remainIDs = append(remainIDs, info.ID) } } @@ -441,6 +442,7 @@ func (e *EventBus) dispatchEvents(ctx context.Context, eventPOs []*EventPO) (fai } }() if err := e.cb(ctx, po.Event); err != nil { + // slice 线程不安全,需要加锁 eventBusMu.Lock() defer eventBusMu.Unlock() failed = append(failed, po.ID)