Skip to content

Commit

Permalink
cgrates: handle inter-mixing of requests and events
Browse files Browse the repository at this point in the history
In case when OpenSIPS sends a request, but before receiving the reply on
the same connection, it receives an event, we need to make sure the
reply is not marked as completed.
Before this fix, when the actual reply was coming back, we no longer had
a reply handler, therefore OpenSIPS was crashing.

Reported by Vasilios Tzanoudakis (vtzan on GitHub) in ticket #1713
  • Loading branch information
razvancrainea committed May 29, 2019
1 parent 382f6e3 commit c90d251
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion modules/cgrates/cgrates_common.c
Expand Up @@ -597,7 +597,8 @@ static int cgrates_async_resume_repl(int fd,

ret = cgrc_async_read(c, cp->reply_f, cp->reply_p);

if (async_status == ASYNC_DONE) {
switch (async_status) {
case ASYNC_DONE:
/* processing done - remove the FD and replace the handler */
async_status = ASYNC_DONE_NO_IO;
reactor_del_reader(c->fd, -1, 0);
Expand All @@ -606,6 +607,9 @@ static int cgrates_async_resume_repl(int fd,
ret = -1;
goto end;
}
break;
case ASYNC_CONTINUE:
return 1;
}
end:
/* done with this connection */
Expand Down Expand Up @@ -759,6 +763,14 @@ int cgrc_async_read(struct cgr_conn *c,
}
/* all done */
json_tokener_reset(c->jtok);
/* if a request was processed and we were waiting for a reply, indicate
* that we shold continue reading from this socket, otherwise we will
* wrongfully waiting for a reply
*/
if (ret == 0 && f) {
async_status = ASYNC_CONTINUE;
return 1;
}
done:
async_status = ASYNC_DONE;
return final_ret;
Expand Down

0 comments on commit c90d251

Please sign in to comment.