@@ -125,7 +125,7 @@ func NewDestination[T any](f Flusher[T], e ErrorHandler[T], opts ...OptFunc) *De
125
125
cfg .StopTimeout = 0
126
126
}
127
127
128
- return & Destination [T ]{
128
+ d := & Destination [T ]{
129
129
flushlen : cfg .FlushLength ,
130
130
flushq : make (chan struct {}, cfg .FlushParallelism ),
131
131
flusher : f ,
@@ -139,6 +139,9 @@ func NewDestination[T any](f Flusher[T], e ErrorHandler[T], opts ...OptFunc) *De
139
139
messages : make (chan msgAck [T ]),
140
140
}
141
141
142
+ slog .Info (fmt .Sprintf ("batcher init, dest: %p, msgs: %p" , d , d .messages ))
143
+
144
+ return d
142
145
}
143
146
144
147
type msgAck [T any ] struct {
@@ -188,10 +191,16 @@ func (d *Destination[T]) Run(ctx context.Context) error {
188
191
}
189
192
d .syncMu .Unlock ()
190
193
194
+ deadlockTimer := time .NewTimer (5 * time .Minute )
195
+
191
196
var err error
192
197
loop:
193
198
for {
194
199
select {
200
+ case <- deadlockTimer .C :
201
+ slog .Info (fmt .Sprintf ("batcher deadlock, dest: %p, msgs: %p" , d , d .messages ))
202
+ return errDeadlock
203
+
195
204
case msg := <- d .messages : // Here
196
205
d .count ++
197
206
if setTimer {
@@ -200,6 +209,12 @@ loop:
200
209
time .AfterFunc (d .flushfreq , func () {
201
210
epochC <- epc // Here
202
211
})
212
+
213
+ if ! deadlockTimer .Stop () {
214
+ <- deadlockTimer .C
215
+ }
216
+ deadlockTimer .Reset (5 * time .Minute )
217
+
203
218
setTimer = false
204
219
}
205
220
d .buf = append (d .buf , msg )
0 commit comments