8000 fix undefined behavior in Scheduler calculations (#9538) · arangodb/arangodb@2209d56 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2209d56

Browse files
jsteemannKVS85
authored andcommitted
fix undefined behavior in Scheduler calculations (#9538)
1 parent d5840c1 commit 2209d56

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

arangod/Scheduler/SupervisedScheduler.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,26 @@ void SupervisedScheduler::runWorker() {
309309

310310
{
311311
std::lock_guard<std::mutex> guard(_mutexSupervisor);
312-
id = _numWorkers++; // increase the number of workers here, to obtains the id
312+
id = _numWorkers++; // increase the number of workers here, to obtain the id
313313
// copy shared_ptr with worker state
314314
state = _workerStates.back();
315315
// inform the supervisor that this thread is alive
316316
_conditionSupervisor.notify_one();
317317
}
318318

319319
state->_sleepTimeout_ms = 20 * (id + 1);
320-
state->_queueRetryCount = (512 >> id) + 3;
320+
// cap the timeout to some boundary value
321+
if (state->_sleepTimeout_ms >= 1000) {
322+
state->_sleepTimeout_ms = 1000;
323+
}
324+
325+
if (id < 32) {
326+
// 512 >> 32 => undefined behavior
327+
state->_queueRetryCount = (512 >> id) + 3;
328+
} else {
329+
// we want at least 3 retries
330+
state->_queueRetryCount = 3;
331+
}
321332

322333
while (true) {
323334
std::unique_ptr<WorkItem> work = getWork(state);

0 commit comments

Comments
 (0)
0