fix(go): protect durable spool replay during shutdown
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user