diff --git a/src/Disks/IDisk.cpp b/src/Disks/IDisk.cpp index 14d5f94ef46..0f17aabd210 100644 --- a/src/Disks/IDisk.cpp +++ b/src/Disks/IDisk.cpp @@ -151,17 +151,19 @@ void IDisk::copyThroughBuffers( { ResultsCollector results; + SCOPE_EXIT_SAFE( + for (auto & result : results) + result.wait(); + for (auto & result : results) + result.get(); /// May rethrow an exception + ); + /// Disable parallel write. We already copy in parallel. /// Avoid high memory usage. See test_s3_zero_copy_ttl/test.py::test_move_and_s3_memory_usage write_settings.s3_allow_parallel_part_upload = false; write_settings.azure_allow_parallel_part_upload = false; asyncCopy(*this, from_path, *to_disk, to_path, copying_thread_pool, results, copy_root_dir, read_settings, write_settings, cancellation_hook); - - for (auto & result : results) - result.wait(); - for (auto & result : results) - result.get(); /// May rethrow an exception }