Skip to content

Commit

Permalink
properly handle async functions when reactor cannot fullfil the request
Browse files Browse the repository at this point in the history
Credits go to 46labs for debugging this

(cherry picked from commit c18c8ea)
  • Loading branch information
razvancrainea committed Oct 29, 2015
1 parent e37bdab commit 025eb66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion modules/dialog/dialog.c
Expand Up @@ -667,7 +667,8 @@ static void ctx_dlg_idx_destroy(void *v)
{
unref_dlg((struct dlg_cell*)v, 1);
/* reset the pointer to make sure no-one is trying to free it anymore */
ctx_dialog_set(NULL);
if (current_processing_ctx)
ctx_dialog_set(NULL);
}


Expand Down
12 changes: 10 additions & 2 deletions modules/tm/async.c
Expand Up @@ -147,7 +147,7 @@ int t_resume_async(int fd, void *param)

int t_handle_async(struct sip_msg *msg, struct action* a , int resume_route)
{
async_ctx *ctx;
async_ctx *ctx = NULL;
async_resume_module *ctx_f;
void *ctx_p;
struct cell *t;
Expand Down Expand Up @@ -230,14 +230,22 @@ int t_handle_async(struct sip_msg *msg, struct action* a , int resume_route)
/* place the FD + resume function (as param) into reactor */
if (reactor_add_reader( fd, F_SCRIPT_ASYNC, RCT_PRIO_ASYNC, (void*)ctx)<0 ) {
LM_ERR("failed to add async FD to reactor -> act in sync mode\n");
shm_free(ctx);
goto sync;
}

/* done, break the script */
return 0;

sync:
if (ctx) {
/*
* the context was moved in reactor, but the reactor could not
* fullfil the request - we have to restore the environment -- razvanc
*/
current_processing_ctx = ctx->msg_ctx;
set_t(t);
shm_free(ctx);
}
/* run the resume function */
do {
return_code = ctx_f( fd, msg, ctx_p );
Expand Down

0 comments on commit 025eb66

Please sign in to comment.