fix(go): protect durable spool replay during shutdown

This commit is contained in:
lingniu
2026-07-02 13:25:15 +08:00
parent 640f70636d
commit bc9025d566
2 changed files with 55 additions and 1 deletions

View File

@@ -37,6 +37,8 @@ type durableRecordFile struct {
record durableRecord
}
const durableReplayOperationTimeout = 30 * time.Second
func NewDurableSink(delegate Sink, cfg DurableConfig) *DurableSink {
if delegate == nil {
panic("durable delegate sink must not be nil")
@@ -130,13 +132,19 @@ func (s *DurableSink) ReplayLoop(ctx context.Context, interval time.Duration, on
case <-ctx.Done():
return
case <-ticker.C:
if err := s.ReplayOnce(ctx); err != nil && onError != nil {
if err := s.replayOnceFromLoop(ctx); err != nil && onError != nil {
onError(err)
}
}
}
}
func (s *DurableSink) replayOnceFromLoop(ctx context.Context) error {
replayCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), durableReplayOperationTimeout)
defer cancel()
return s.ReplayOnce(replayCtx)
}
func (s *DurableSink) Close() error {
return s.delegate.Close()
}