[Asterisk-code-review] res pjsip: Handle invocation of callback on outgoing request... (asterisk[master])

Joshua Colp asteriskteam at digium.com
Tue Jan 31 11:25:07 CST 2017


Joshua Colp has uploaded a new change for review. ( https://gerrit.asterisk.org/4848 )

Change subject: res_pjsip: Handle invocation of callback on outgoing request when error occurs.
......................................................................

res_pjsip: Handle invocation of callback on outgoing request when error occurs.

There are some error cases in PJSIP when sending a request that will
result in the callback for the request being invoked. The code did not
handle this case and assumed on every error case that the callback was
not invoked.

The code has been changed to check whether the callback has been invoked and
if so to absord the error and treat it as a success.

ASTERISK-26679

Change-Id: I563982ba204da5aa1428989a11c06dd9087fea91
---
M res/res_pjsip.c
1 file changed, 12 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/48/4848/1

diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index a7dd09e..e71e146 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -3540,6 +3540,7 @@
 	pj_status_t ret_val;
 	pjsip_endpoint *endpt = ast_sip_get_pjsip_endpoint();
 	pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
+	char errmsg[PJ_ERR_MSG_SIZE];
 
 	if (!cb && token) {
 		/* Silly.  Without a callback we cannot do anything with token. */
@@ -3601,14 +3602,20 @@
 	 */
 	ao2_ref(req_wrapper, +1);
 	ret_val = pjsip_endpt_send_request(endpt, tdata, -1, req_wrapper, endpt_send_request_cb);
-	if (ret_val != PJ_SUCCESS) {
-		char errmsg[PJ_ERR_MSG_SIZE];
+	if (req_wrapper->cb_called) {
+		pj_strerror(ret_val, errmsg, sizeof(errmsg));
+		ast_log(LOG_ERROR, "Error %d '%s' sending %.*s request to endpoint %s\n",
+			(int) ret_val, errmsg, (int) pj_strlen(&tdata->msg->line.req.method.name),
+			pj_strbuf(&tdata->msg->line.req.method.name),
+			endpoint ? ast_sorcery_object_get_id(endpoint) : "<unknown>");
 
 		/*
-		 * endpt_send_request_cb is not expected to ever be called
-		 * because the request didn't get far enough to attempt
-		 * sending.
+		 * If the callback has been invoked absord any failure and turn it into a success
+		 * so the caller of this function does not try to perform any cleanup.
 		 */
+		ret_val = PJ_SUCCESS;
+	} else if (ret_val != PJ_SUCCESS) {
+		/* The callback was never invoked so we drop its reference */
 		ao2_ref(req_wrapper, -1);
 
 		/* Complain of failure to send the request. */

-- 
To view, visit https://gerrit.asterisk.org/4848
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I563982ba204da5aa1428989a11c06dd9087fea91
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list