Fix overflow in exponential sleep in DirectoryMonitor

UBsan reports:

    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../src/Storages/Distributed/DirectoryMonitor.cpp:435:53 in
    ../src/Storages/Distributed/DirectoryMonitor.cpp:435: runtime error: 1.15292e+19 is outside the range of representable values of type 'long'
        0 0x1df0c286 in DB::StorageDistributedDirectoryMonitor::run() obj-x86_64-linux-gnu/../src/Storages/Distributed/DirectoryMonitor.cpp:435:53

It is pretty easy to reproduce by limiting max_server_memory_usage
before staring the test.
This commit is contained in:
Azat Khuzhin 2021-07-16 04:08:59 +03:00
parent e2d8ba893a
commit a3653bd665

View File

@ -432,7 +432,7 @@ void StorageDistributedDirectoryMonitor::run()
do_sleep = true;
++status.error_count;
sleep_time = std::min(
std::chrono::milliseconds{Int64(default_sleep_time.count() * std::exp2(status.error_count))},
std::chrono::milliseconds{UInt64(default_sleep_time.count() * std::exp2(status.error_count))},
max_sleep_time);
tryLogCurrentException(getLoggerName().data());
status.last_exception = std::current_exception();