[core] Fixed bit-shifting error in exponential backoff
This change fixes a bug introduced in 4d5c6333be for #2727. 1 << 32 would exceed the size of int64_t. The static analyzer reported undefined behavior here because std::min() might or might not return 32.
This commit is contained in:
@@ -325,12 +325,12 @@ int64_t DefaultFileRequest::getRetryTimeout() const {
|
||||
if (failedRequests <= graceRetries) {
|
||||
timeout = 1;
|
||||
} else {
|
||||
timeout = 1 << std::min(failedRequests - graceRetries, 32);
|
||||
timeout = 1 << std::min(failedRequests - graceRetries, 31);
|
||||
}
|
||||
} break;
|
||||
case Response::Error::Reason::Connection: {
|
||||
// Exponential backoff
|
||||
timeout = 1 << std::min(failedRequests - 1, 32);
|
||||
timeout = 1 << std::min(failedRequests - 1, 31);
|
||||
} break;
|
||||
default:
|
||||
// Do not retry due to error.
|
||||
|
||||
Reference in New Issue
Block a user