From 53a6e9683589988971751256c4cd96cba79d07ab Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 7 Aug 2018 14:29:27 +0300 Subject: fixes #628 Hang in closing REQ This adds a proper boolean condition for the pipe being closed (removing the unused sending flag), and adds checks for both the pipe closed and the socket closed flags at key points. --- src/protocol/reqrep0/req.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/protocol/reqrep0/req.c') diff --git a/src/protocol/reqrep0/req.c b/src/protocol/reqrep0/req.c index 018dd0e8..59dd73b4 100644 --- a/src/protocol/reqrep0/req.c +++ b/src/protocol/reqrep0/req.c @@ -82,8 +82,8 @@ struct req0_pipe { nni_pipe * pipe; req0_sock * req; nni_list_node node; - nni_list ctxs; // ctxs with pending traffic - bool sending; // if busy sending + nni_list ctxs; // ctxs with pending traffic + bool closed; nni_aio * aio_send; nni_aio * aio_recv; }; @@ -265,7 +265,7 @@ req0_pipe_close(void *arg) nni_mtx_lock(&s->mtx); // This removes the node from either busypipes or readypipes. // It doesn't much matter which. - p->sending = false; + p->closed = true; if (nni_list_node_active(&p->node)) { nni_list_node_remove(&p->node); if (s->closed) { @@ -313,7 +313,7 @@ req0_send_cb(void *arg) // in the ready list, and re-run the sendq. nni_mtx_lock(&s->mtx); - if (!p->sending) { + if (p->closed || s->closed) { // This occurs if the req0_pipe_close has been called. // In that case we don't want any more processing. nni_mtx_unlock(&s->mtx); @@ -321,7 +321,6 @@ req0_send_cb(void *arg) } nni_list_remove(&s->busypipes, p); nni_list_append(&s->readypipes, p); - p->sending = false; if (nni_list_empty(&s->sendq)) { nni_pollable_raise(s->sendable); } @@ -534,7 +533,6 @@ req0_run_sendq(req0_sock *s, nni_list *aiolist) nni_list_remove(&s->readypipes, p); nni_list_append(&s->busypipes, p); - p->sending = true; if ((aio = ctx->saio) != NULL) { ctx->saio = NULL; @@ -715,6 +713,11 @@ req0_ctx_send(void *arg, nni_aio *aio) return; } nni_mtx_lock(&s->mtx); + if (s->closed) { + nni_mtx_unlock(&s->mtx); + nni_aio_finish_error(aio, NNG_ECLOSED); + return; + } // Sending a new request cancels the old one, including any // outstanding reply. if (ctx->raio != NULL) { -- cgit v1.2.3-70-g09d2