diff options
| author | Garrett D'Amore <garrett@damore.org> | 2019-02-17 10:17:26 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2019-02-17 10:17:26 -0800 |
| commit | 8ac664fdbab302c9e8cd16a1d45ace5bd00046e5 (patch) | |
| tree | 060f462549182d1b56c8868b70d238989764491b /src | |
| parent | 60231f0600461a9593a8f876518874866df3387a (diff) | |
| download | nng-8ac664fdbab302c9e8cd16a1d45ace5bd00046e5.tar.gz nng-8ac664fdbab302c9e8cd16a1d45ace5bd00046e5.tar.bz2 nng-8ac664fdbab302c9e8cd16a1d45ace5bd00046e5.zip | |
fixes #871 panic when sharing rep between threads
Diffstat (limited to 'src')
| -rw-r--r-- | src/protocol/reqrep0/rep.c | 10 | ||||
| -rw-r--r-- | src/protocol/survey0/respond.c | 11 |
2 files changed, 18 insertions, 3 deletions
diff --git a/src/protocol/reqrep0/rep.c b/src/protocol/reqrep0/rep.c index 5f856f8e..2d00b65f 100644 --- a/src/protocol/reqrep0/rep.c +++ b/src/protocol/reqrep0/rep.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -482,6 +482,14 @@ rep0_ctx_recv(void *arg, nni_aio *aio) nni_aio_finish_error(aio, rv); return; } + if (ctx->raio != NULL) { + // Cannot have a second receive operation pending. + // This could be ESTATE, or we could cancel the first + // with ECANCELED. We elect the former. + nni_mtx_unlock(&s->lk); + nni_aio_finish_error(aio, NNG_ESTATE); + return; + } ctx->raio = aio; nni_list_append(&s->recvq, ctx); nni_mtx_unlock(&s->lk); diff --git a/src/protocol/survey0/respond.c b/src/protocol/survey0/respond.c index caecf719..bb457bdb 100644 --- a/src/protocol/survey0/respond.c +++ b/src/protocol/survey0/respond.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -123,7 +123,7 @@ resp0_ctx_init(void **ctxp, void *sarg) return (NNG_ENOMEM); } NNI_LIST_NODE_INIT(&ctx->sqnode); - // XXX: NNI_LIST_NODE_INIT(&ctx->rqnode); + NNI_LIST_NODE_INIT(&ctx->rqnode); ctx->btrace_len = 0; ctx->sock = s; ctx->pipe_id = 0; @@ -472,6 +472,13 @@ resp0_ctx_recv(void *arg, nni_aio *aio) nni_aio_finish_error(aio, rv); return; } + // We cannot have two concurrent receive requests on the same + // context... + if (ctx->raio != NULL) { + nni_mtx_unlock(&s->mtx); + nni_aio_finish_error(aio, NNG_ESTATE); + return; + } ctx->raio = aio; nni_list_append(&s->recvq, ctx); nni_mtx_unlock(&s->mtx); |
