Skip to content

Commit

Permalink
HG Core: fix potential race when forcing a handle to be destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
soumagne committed Dec 7, 2018
1 parent fac0449 commit a421ea3
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/mercury_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3362,6 +3362,9 @@ hg_core_trigger_entry(struct hg_core_handle *hg_core_handle)
hg_return_t ret = HG_SUCCESS;

if (hg_core_handle->op_type == HG_CORE_PROCESS) {
/* Take another reference to make sure the handle does not get freed */
hg_atomic_incr32(&hg_core_handle->ref_count);

/* Run RPC callback */
ret = hg_core_process(hg_core_handle);
if (ret != HG_SUCCESS && !hg_core_handle->no_response) {
Expand Down Expand Up @@ -3431,19 +3434,20 @@ hg_core_trigger_entry(struct hg_core_handle *hg_core_handle)
/* Execute user callback */
if (hg_cb)
hg_cb(&hg_core_cb_info);

/* Repost handle if we were listening, otherwise destroy it */
if (hg_core_handle->repost && !hg_core_handle->hg_info.context->finalizing) {
/* Repost handle */
ret = hg_core_reset_post(hg_core_handle);
if (ret != HG_SUCCESS) {
HG_LOG_ERROR("Cannot repost handle");
goto done;
}
} else
hg_core_destroy(hg_core_handle);
}

/* Repost handle if we were listening, otherwise destroy it */
if (hg_core_handle->repost
&& !hg_core_handle->hg_info.context->finalizing) {
/* Repost handle */
ret = hg_core_reset_post(hg_core_handle);
if (ret != HG_SUCCESS) {
HG_LOG_ERROR("Cannot repost handle");
goto done;
}
} else
hg_core_destroy(hg_core_handle);

done:
return ret;
}
Expand Down

0 comments on commit a421ea3

Please sign in to comment.