Skip to content

Commit eaa20d7

Browse files
cjen1-msfteddyashtonachamayou
authored
Fix uv_loop_close sequence to wait for in-flight synchronous calls that hold uv resources (#7070)
Co-authored-by: Eddy Ashton <[email protected]> Co-authored-by: Amaury Chamayou <[email protected]>
1 parent 8ce9503 commit eaa20d7

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/host/run.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,21 +1018,23 @@ namespace ccf
10181018

10191019
process_launcher.stop();
10201020

1021-
// Continue running the loop long enough for the on_close
1022-
// callbacks to be despatched, so as to avoid memory being
1023-
// leaked by handles. Capped out of abundance of caution.
1024-
constexpr size_t max_iterations = 1000;
1025-
size_t close_iterations = max_iterations;
1026-
while ((uv_loop_alive(uv_default_loop()) != 0) && (close_iterations > 0))
1021+
constexpr size_t max_close_iterations = 1000;
1022+
size_t close_iterations = max_close_iterations;
1023+
int loop_close_rc = 0;
1024+
while (close_iterations > 0)
10271025
{
1026+
loop_close_rc = uv_loop_close(uv_default_loop());
1027+
if (loop_close_rc != UV_EBUSY)
1028+
{
1029+
break;
1030+
}
10281031
uv_run(uv_default_loop(), UV_RUN_NOWAIT);
1029-
close_iterations--;
1032+
--close_iterations;
1033+
std::this_thread::sleep_for(10ms);
10301034
}
10311035
LOG_INFO_FMT(
10321036
"Ran an extra {} cleanup iteration(s)",
1033-
max_iterations - close_iterations);
1034-
1035-
auto loop_close_rc = uv_loop_close(uv_default_loop());
1037+
max_close_iterations - close_iterations);
10361038
if (loop_close_rc != 0)
10371039
{
10381040
LOG_FAIL_FMT(

0 commit comments

Comments
 (0)