From a1d237059c652c9e36117eed3e6387dcae128174 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 15 Jul 2017 18:45:02 -0700 Subject: Add missing cancellation for inproc endpoints -- the source of much woe. Most of the races around close were probably here - the cancellation was not getting through on endpoint close, which meant that we could actually toss endpoints while they were in use. We need to fix the timeouts stuff -- especially for reconnects etc, but we are just about ready for this stuff to be reintegrated into master. --- src/transport/inproc/inproc.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src') diff --git a/src/transport/inproc/inproc.c b/src/transport/inproc/inproc.c index 78a0c44a..984ee8f5 100644 --- a/src/transport/inproc/inproc.c +++ b/src/transport/inproc/inproc.c @@ -363,6 +363,24 @@ nni_inproc_accept_clients(nni_inproc_ep *server) } } +static void +nni_inproc_ep_cancel(nni_aio *aio) +{ + nni_inproc_ep *ep = aio->a_prov_data; + + nni_mtx_lock(&nni_inproc.mx); + if (nni_list_active(&ep->aios, aio)) { + nni_list_remove(&ep->aios, aio); + } + // Arguably if the mode is a client... then we need to remove + // it from the server's list. Notably this isn't *our* list, + // but the offsets are the same and they're good enough using the + // global lock to make it all safe. + if (nni_list_active(&ep->clients, ep)) { + nni_list_remove(&ep->clients, ep); + } + nni_mtx_unlock(&nni_inproc.mx); +} static void nni_inproc_ep_connect(void *arg, nni_aio *aio) { @@ -390,6 +408,11 @@ nni_inproc_ep_connect(void *arg, nni_aio *aio) } nni_mtx_lock(&nni_inproc.mx); + + if ((rv = nni_aio_start(aio, nni_inproc_ep_cancel, ep)) != 0) { + nni_mtx_unlock(&nni_inproc.mx); + return; + } aio->a_pipe = pipe; if (nni_list_active(&ep->clients, ep)) { @@ -491,6 +514,10 @@ nni_inproc_ep_accept(void *arg, nni_aio *aio) return; } + if ((rv = nni_aio_start(aio, nni_inproc_ep_cancel, ep)) != 0) { + nni_mtx_unlock(&nni_inproc.mx); + return; + } aio->a_pipe = pipe; // Insert us into the pending server aios, and then run the -- cgit v1.2.3-70-g09d2