Skip to content

Commit 9128757

Browse files
committed
check for nil in lifo unblock
1 parent cba3c8a commit 9128757

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

limiter/lifo_blocking.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ func (l *LifoBlockingListener) unblock() {
122122
if l.limiter.backlog.len() > 0 {
123123

124124
evict, nextEvent := l.limiter.backlog.peek()
125+
126+
// Last element expired between us checking the
127+
// queue length and invoking peek
128+
if nextEvent == nil {
129+
return
130+
}
131+
125132
listener, ok := l.limiter.delegate.Acquire(nextEvent.ctx)
126133

127134
if ok && listener != nil {
@@ -175,7 +182,6 @@ type LifoBlockingLimiter struct {
175182
maxBacklogTimeout time.Duration
176183

177184
backlog lifoQueue
178-
c *sync.Cond
179185
mu sync.RWMutex
180186
}
181187

@@ -191,13 +197,11 @@ func NewLifoBlockingLimiter(
191197
if maxBacklogTimeout == 0 {
192198
maxBacklogTimeout = time.Millisecond * 1000
193199
}
194-
mu := sync.Mutex{}
195200
return &LifoBlockingLimiter{
196201
delegate: delegate,
197202
maxBacklogSize: uint64(maxBacklogSize),
198203
maxBacklogTimeout: maxBacklogTimeout,
199204
backlog: lifoQueue{},
200-
c: sync.NewCond(&mu),
201205
}
202206
}
203207

0 commit comments

Comments
 (0)