diff --git a/cpp/src/endpoint.cpp b/cpp/src/endpoint.cpp index 6ec80577..e795f71c 100644 --- a/cpp/src/endpoint.cpp +++ b/cpp/src/endpoint.cpp @@ -162,7 +162,7 @@ void Endpoint::close(uint64_t period, uint64_t maxAttempts) if (worker->isProgressThreadRunning()) { bool closeSuccess = false; - for (uint64_t i = 0; i < maxAttempts; ++i) { + for (uint64_t i = 0; i < maxAttempts && !closeSuccess; ++i) { utils::CallbackNotifier callbackNotifierPre{}; worker->registerGenericPre([this, &callbackNotifierPre, &status, closeMode]() { status = ucp_ep_close_nb(_handle, closeMode); @@ -277,7 +277,7 @@ size_t Endpoint::cancelInflightRequests(uint64_t period, uint64_t maxAttempts) worker->progress(); } else if (worker->isProgressThreadRunning()) { bool cancelSuccess = false; - for (uint64_t i = 0; i < maxAttempts; ++i) { + for (uint64_t i = 0; i < maxAttempts && !cancelSuccess; ++i) { utils::CallbackNotifier callbackNotifierPre{}; worker->registerGenericPre([this, &callbackNotifierPre, &canceled]() { canceled = _inflightRequests->cancelAll(); diff --git a/cpp/src/worker.cpp b/cpp/src/worker.cpp index 8290534e..cb4dc50b 100644 --- a/cpp/src/worker.cpp +++ b/cpp/src/worker.cpp @@ -414,7 +414,7 @@ size_t Worker::cancelInflightRequests(uint64_t period, uint64_t maxAttempts) progressPending(); } else if (isProgressThreadRunning()) { bool cancelSuccess = false; - for (uint64_t i = 0; i < maxAttempts; ++i) { + for (uint64_t i = 0; i < maxAttempts && !cancelSuccess; ++i) { utils::CallbackNotifier callbackNotifierPre{}; registerGenericPre([&callbackNotifierPre, &canceled, &inflightRequestsToCancel]() { canceled = inflightRequestsToCancel->cancelAll();