Added yields to prevent stack overflows from too many callbacks when queue operations accumulate waiting on IO.

This commit is contained in:
Steve Atherton 2021-06-06 02:04:20 -07:00
parent 3af0bea46c
commit 46c4f6fd47
1 changed files with 18 additions and 1 deletions

View File

@ -516,6 +516,14 @@ public:
++self->queue->numEntries;
if (mustWait || needNewPage) {
// Prevent possible stack overflow if too many waiters which require no IO are queued up
// Using static because multiple Cursors can be involved
static int sinceYield = 0;
if (++sinceYield == 1000) {
sinceYield = 0;
wait(yield());
}
self->mutex.release();
}
@ -551,10 +559,18 @@ public:
wait(success(self->nextPageReader));
}
Optional<T> result = wait(self->readNext(upperBound, true));
state Optional<T> result = wait(self->readNext(upperBound, true));
// If this actor instance locked the mutex, then unlock it.
if (!locked) {
// Prevent possible stack overflow if too many waiters which require no IO are queued up
// Using static because multiple Cursors can be involved
static int sinceYield = 0;
if (++sinceYield == 1000) {
sinceYield = 0;
wait(yield());
}
debug_printf("FIFOQueue::Cursor(%s) waitThenReadNext unlocking mutex\n", self->toString().c_str());
self->mutex.release();
}
@ -2116,6 +2132,7 @@ public:
break;
}
// Yield to prevent slow task in case no IO waits are encountered
if (++sinceYield >= 100) {
sinceYield = 0;
wait(yield());