|
18 | 18 | package memqueue
|
19 | 19 |
|
20 | 20 | import (
|
21 |
| - "fmt" |
22 | 21 | "time"
|
23 | 22 |
|
24 | 23 | "github.com/elastic/beats/v7/libbeat/common/fifo"
|
@@ -153,8 +152,9 @@ func (l *runLoop) runIteration() {
|
153 | 152 | select {
|
154 | 153 | case <-l.broker.closeChan:
|
155 | 154 | l.closing = true
|
156 |
| - // Get requests are handled immediately during shutdown |
| 155 | + // Get and push requests are handled immediately during shutdown |
157 | 156 | l.maybeUnblockGetRequest()
|
| 157 | + l.maybeUnblockPushRequests() |
158 | 158 |
|
159 | 159 | case <-l.broker.ctx.Done():
|
160 | 160 | // The queue is fully shut down, do nothing
|
@@ -205,11 +205,10 @@ func (l *runLoop) getRequestShouldBlock(req *getRequest) bool {
|
205 | 205 | // limit) or if we have at least the requested number available.
|
206 | 206 | if l.broker.useByteLimits() {
|
207 | 207 | availableBytes := l.byteCount - l.consumedByteCount
|
208 |
| - return req.byteCount <= 0 || availableBytes >= req.byteCount |
| 208 | + return req.byteCount > 0 && availableBytes < req.byteCount |
209 | 209 | }
|
210 | 210 | availableEntries := l.eventCount - l.consumedEventCount
|
211 |
| - fmt.Printf("hi fae, getRequestShouldBlock for %v entries while there are %v available\n", req.entryCount, availableEntries) |
212 |
| - return req.entryCount <= 0 || availableEntries >= req.entryCount |
| 211 | + return req.entryCount > 0 && availableEntries < req.entryCount |
213 | 212 | }
|
214 | 213 |
|
215 | 214 | // Respond to the given get request without blocking or waiting for more events
|
@@ -316,7 +315,14 @@ func (l *runLoop) canFitPushRequest(req pushRequest) bool {
|
316 | 315 | func (l *runLoop) maybeUnblockPushRequests() {
|
317 | 316 | for !l.pendingPushRequests.Empty() {
|
318 | 317 | req := l.pendingPushRequests.First()
|
| 318 | + if l.closing { |
| 319 | + // If the queue is closing, reject all pending requests |
| 320 | + req.resp <- false |
| 321 | + continue |
| 322 | + } |
319 | 323 | if !l.canFitPushRequest(req) {
|
| 324 | + // We're out of space, the rest of the blocked requests will have |
| 325 | + // to wait. |
320 | 326 | break
|
321 | 327 | }
|
322 | 328 | l.doInsert(req)
|
|
0 commit comments