Skip to content

Commit

Permalink
BUGFIX prevent specific rare deadlocks
Browse files Browse the repository at this point in the history
Fixes #233
  • Loading branch information
michalvasko committed Sep 15, 2016
1 parent 4190f35 commit a2da916
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -2402,6 +2402,9 @@ API NC_MSG_TYPE nc_session_recv_reply(struct nc_session* session, int timeout, n

ret = nc_session_recv_msg(session, local_timeout, &msg);

DBG_UNLOCK("mut_mqueue");
pthread_mutex_unlock(&(session->mut_mqueue));

switch (ret) {
case NC_MSG_REPLY: /* regular reply received */
/* if specified callback for processing rpc-error, use it */
Expand Down Expand Up @@ -2435,6 +2438,9 @@ API NC_MSG_TYPE nc_session_recv_reply(struct nc_session* session, int timeout, n
break;
case NC_MSG_WOULDBLOCK:
if ((timeout == -1) || ((timeout > 0) && ((timeout = timeout - local_timeout) > 0))) {
/* lock again */
DBG_LOCK("mut_mqueue");
pthread_mutex_lock(&(session->mut_mqueue));
goto try_again;
}
break;
Expand All @@ -2460,10 +2466,6 @@ API NC_MSG_TYPE nc_session_recv_reply(struct nc_session* session, int timeout, n
break;
}

/* session lock is no more needed */
DBG_UNLOCK("mut_mqueue");
pthread_mutex_unlock(&(session->mut_mqueue));

return (ret);
}

Expand Down

0 comments on commit a2da916

Please sign in to comment.