aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-07-18 20:23:14 -0700
committerGarrett D'Amore <garrett@damore.org>2017-07-18 20:23:14 -0700
commit9a224b54913818db3080b13cc1183d5bb3926247 (patch)
tree211ef8425d6bf9d79dea539c92940c1286c61286 /src
parent5fb832e06fd4ded6ccc45f943837fd374a9cea7a (diff)
downloadnng-9a224b54913818db3080b13cc1183d5bb3926247.tar.gz
nng-9a224b54913818db3080b13cc1183d5bb3926247.tar.bz2
nng-9a224b54913818db3080b13cc1183d5bb3926247.zip
fixes #21 Crash in IPC (POSIX)
This resolves the orphaned pipedesc, which actually could have affected Windows too. I think maybe we are race free. Lots more testing is still required, but stress runs seem to be passing now.
Diffstat (limited to 'src')
-rw-r--r--src/transport/ipc/ipc.c22
-rw-r--r--src/transport/tcp/tcp.c26
2 files changed, 19 insertions, 29 deletions
diff --git a/src/transport/ipc/ipc.c b/src/transport/ipc/ipc.c
index 862cf955..65266ccc 100644
--- a/src/transport/ipc/ipc.c
+++ b/src/transport/ipc/ipc.c
@@ -527,14 +527,10 @@ nni_ipc_ep_bind(void *arg)
static void
nni_ipc_ep_finish(nni_ipc_ep *ep)
{
- nni_aio * aio = ep->user_aio;
- nni_ipc_pipe *pipe;
+ nni_aio * aio;
int rv;
+ nni_ipc_pipe *pipe = NULL;
- if ((aio = ep->user_aio) == NULL) {
- return;
- }
- ep->user_aio = NULL;
if ((rv = nni_aio_result(&ep->aio)) != 0) {
goto done;
}
@@ -542,17 +538,15 @@ nni_ipc_ep_finish(nni_ipc_ep *ep)
// Attempt to allocate the parent pipe. If this fails we'll
// drop the connection (ENOMEM probably).
- if ((rv = nni_ipc_pipe_init(&pipe, ep, ep->aio.a_pipe)) != 0) {
- nni_plat_ipc_pipe_fini(ep->aio.a_pipe);
- goto done;
- }
-
- aio->a_pipe = pipe;
+ rv = nni_ipc_pipe_init(&pipe, ep, ep->aio.a_pipe);
done:
ep->aio.a_pipe = NULL;
- if (nni_aio_finish(aio, rv, 0) != 0) {
- if (rv == 0) {
+ aio = ep->user_aio;
+ ep->user_aio = NULL;
+
+ if ((aio == NULL) || (nni_aio_finish_pipe(aio, rv, pipe) != 0)) {
+ if (pipe != NULL) {
nni_ipc_pipe_fini(pipe);
}
}
diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c
index 23472883..13d5716a 100644
--- a/src/transport/tcp/tcp.c
+++ b/src/transport/tcp/tcp.c
@@ -594,14 +594,10 @@ nni_tcp_ep_bind(void *arg)
static void
nni_tcp_ep_finish(nni_tcp_ep *ep)
{
- nni_aio * aio = ep->user_aio;
- nni_tcp_pipe *pipe;
+ nni_aio * aio;
int rv;
+ nni_tcp_pipe *pipe = NULL;
- if ((aio = ep->user_aio) == NULL) {
- return;
- }
- ep->user_aio = NULL;
if ((rv = nni_aio_result(&ep->aio)) != 0) {
goto done;
}
@@ -609,17 +605,15 @@ nni_tcp_ep_finish(nni_tcp_ep *ep)
// Attempt to allocate the parent pipe. If this fails we'll
// drop the connection (ENOMEM probably).
- if ((rv = nni_tcp_pipe_init(&pipe, ep, ep->aio.a_pipe)) != 0) {
- nni_plat_tcp_pipe_fini(ep->aio.a_pipe);
- goto done;
- }
-
- aio->a_pipe = pipe;
+ rv = nni_tcp_pipe_init(&pipe, ep, ep->aio.a_pipe);
done:
ep->aio.a_pipe = NULL;
- if (nni_aio_finish(aio, rv, 0) != 0) {
- if (rv == 0) {
+ aio = ep->user_aio;
+ ep->user_aio = NULL;
+
+ if ((aio == NULL) || (nni_aio_finish_pipe(aio, rv, pipe) != 0)) {
+ if (pipe != NULL) {
nni_tcp_pipe_fini(pipe);
}
}
@@ -654,11 +648,13 @@ nni_tcp_ep_accept(void *arg, nni_aio *aio)
int rv;
nni_mtx_lock(&ep->mtx);
+ NNI_ASSERT(ep->user_aio == NULL);
+
if (ep->closed) {
nni_aio_finish(aio, NNG_ECLOSED, 0);
nni_mtx_unlock(&ep->mtx);
+ return;
}
- NNI_ASSERT(ep->user_aio == NULL);
ep->user_aio = aio;
if ((rv = nni_aio_start(aio, nni_tcp_cancel_ep, ep)) != 0) {