summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-21 14:56:05 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-21 14:56:05 -0800
commit434cdd9f4e9211b99ba62ff6973e082b90e098f0 (patch)
treea4334110a531d6a9b32f3e2e686fa5c113153ef9 /src/core
parent8d3f410962fed3b4a8e6e3962ebf3bb55f5f2b93 (diff)
downloadnng-434cdd9f4e9211b99ba62ff6973e082b90e098f0.tar.gz
nng-434cdd9f4e9211b99ba62ff6973e082b90e098f0.tar.bz2
nng-434cdd9f4e9211b99ba62ff6973e082b90e098f0.zip
Resolve deadlock during close.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/socket.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/core/socket.c b/src/core/socket.c
index b8c5544b..b1f8f2c4 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -47,6 +47,8 @@ nni_sock_hold(nni_sock **sockp, uint32_t id)
}
nni_mtx_lock(nni_idlock);
rv = nni_idhash_find(nni_sockets, id, (void **) &sock);
+ nni_mtx_unlock(nni_idlock);
+
if (rv == 0) {
if (sock->s_closing) {
rv = NNG_ECLOSED;
@@ -57,8 +59,6 @@ nni_sock_hold(nni_sock **sockp, uint32_t id)
*sockp = sock;
}
}
- nni_mtx_unlock(nni_idlock);
-
if (rv == NNG_ENOENT) {
rv = NNG_ECLOSED;
}
@@ -495,6 +495,10 @@ nni_sock_close(nni_sock *sock)
// user code attempts to utilize the socket *after* this point,
// the results may be tragic.
+ nni_mtx_lock(nni_idlock);
+ nni_idhash_remove(nni_sockets, sock->s_id);
+ nni_mtx_unlock(nni_idlock);
+
// The protocol needs to clean up its state.
sock->s_sock_ops.sock_fini(sock->s_data);