[Asterisk-code-review] res sorcery realtime: fix bug when successful UPDATE is trea... (asterisk[13])

Alexei Gradinari asteriskteam at digium.com
Mon Jul 4 16:43:49 CDT 2016


Alexei Gradinari has uploaded a new change for review.

  https://gerrit.asterisk.org/3146

Change subject: res_sorcery_realtime: fix bug when successful UPDATE is treated as failed
......................................................................

res_sorcery_realtime: fix bug when successful UPDATE is treated as failed

If the SQL UPDATE statement changes nothing then SQLRowCount returns 0.
This value should be treated as success.
But the function sorcery_realtime_update treats it as failed.

This bug was found using stress tests on PJSIP.
If there are 2 consecutive SIP REGISTER requests with the same contact data
during 1 second then res_pjsip_registrar adds contact location on 1st request
and tries to update contact location on 2nd.
The update fails and res_pjsip_registrar even removes correct contact location.

This patch also adds missing debug of extra SQL parameter.

ASTERISK-26172 #close

Change-Id: I05a7f3051455336c9dda29efc229decf86071303
---
M res/res_config_odbc.c
M res/res_sorcery_realtime.c
2 files changed, 2 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/46/3146/1

diff --git a/res/res_config_odbc.c b/res/res_config_odbc.c
index 2888d35..2d991a5 100644
--- a/res/res_config_odbc.c
+++ b/res/res_config_odbc.c
@@ -137,6 +137,7 @@
 
 	if (!ast_strlen_zero(cps->extra)) {
 		const char *newval = cps->extra;
+		ast_debug(1, "Parameter %d = '%s'\n", x, newval);
 		if (strchr(newval, ';') || strchr(newval, '^')) {
 			ENCODE_CHUNK(encodebuf, newval);
 			ast_string_field_set(cps, encoding[x], encodebuf);
diff --git a/res/res_sorcery_realtime.c b/res/res_sorcery_realtime.c
index 2c533ea..138d6ea 100644
--- a/res/res_sorcery_realtime.c
+++ b/res/res_sorcery_realtime.c
@@ -271,7 +271,7 @@
 		return -1;
 	}
 
-	return (ast_update_realtime_fields(config->family, UUID_FIELD, ast_sorcery_object_get_id(object), fields) <= 0) ? -1 : 0;
+	return (ast_update_realtime_fields(config->family, UUID_FIELD, ast_sorcery_object_get_id(object), fields) < 0) ? -1 : 0;
 }
 
 static int sorcery_realtime_delete(const struct ast_sorcery *sorcery, void *data, void *object)

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I05a7f3051455336c9dda29efc229decf86071303
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>



More information about the asterisk-code-review mailing list