Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add deadlock timer #54

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion x/batcher/batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func NewDestination[T any](f Flusher[T], e ErrorHandler[T], opts ...OptFunc) *De
cfg.StopTimeout = 0
}

return &Destination[T]{
d := &Destination[T]{
flushlen: cfg.FlushLength,
flushq: make(chan struct{}, cfg.FlushParallelism),
flusher: f,
Expand All @@ -139,6 +139,9 @@ func NewDestination[T any](f Flusher[T], e ErrorHandler[T], opts ...OptFunc) *De
messages: make(chan msgAck[T]),
}

slog.Info(fmt.Sprintf("batcher init, dest: %p, msgs: %p", d, d.messages))

return d
}

type msgAck[T any] struct {
Expand Down Expand Up @@ -188,10 +191,16 @@ func (d *Destination[T]) Run(ctx context.Context) error {
}
d.syncMu.Unlock()

deadlockTimer := time.NewTimer(5 * time.Minute)

var err error
loop:
for {
select {
case <-deadlockTimer.C:
slog.Info(fmt.Sprintf("batcher deadlock, dest: %p, msgs: %p", d, d.messages))
return errDeadlock

case msg := <-d.messages: // Here
d.count++
if setTimer {
Expand All @@ -200,6 +209,12 @@ loop:
time.AfterFunc(d.flushfreq, func() {
epochC <- epc // Here
})

if !deadlockTimer.Stop() {
<-deadlockTimer.C
}
deadlockTimer.Reset(5 * time.Minute)

setTimer = false
}
d.buf = append(d.buf, msg)
Expand Down
Loading