From 4af7478cff16a6c07c986a411f2ae6ebc9979970 Mon Sep 17 00:00:00 2001 From: Alexander Zilberkant Date: Wed, 24 Apr 2024 21:53:35 +0300 Subject: [PATCH] fix deadlock on socket close when an `aio` has no `a_cancel_fn` and the task is in `task_prep` abort it on `nni_aio_stop` call --- src/core/aio.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/aio.c b/src/core/aio.c index 084795bdc..9a21d224b 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -136,6 +136,8 @@ nni_aio_fini(nni_aio *aio) if (fn != NULL) { fn(aio, arg, NNG_ECLOSED); + } else { + nni_task_abort(&aio->a_task); } nni_task_fini(&aio->a_task); @@ -215,6 +217,8 @@ nni_aio_stop(nni_aio *aio) if (fn != NULL) { fn(aio, arg, NNG_ECANCELED); + } else { + nni_task_abort(&aio->a_task); } nni_aio_wait(aio); @@ -240,6 +244,8 @@ nni_aio_close(nni_aio *aio) if (fn != NULL) { fn(aio, arg, NNG_ECLOSED); + } else { + nni_task_abort(&aio->a_task); } } } @@ -439,6 +445,8 @@ nni_aio_abort(nni_aio *aio, int rv) // Stop any I/O at the provider level. if (fn != NULL) { fn(aio, arg, rv); + } else { + nni_task_abort(&aio->a_task); } }