From 9af42f16badfe6e1949cd42b091191204310ce34 Mon Sep 17 00:00:00 2001 From: Julien Chavanton Date: Wed, 4 Jan 2017 09:19:43 -0500 Subject: [PATCH 1/2] dmq_usrloc: fix deadlock caused by acquiring the same lock twice using get_urecord_by_ruid and lock_udomain --- src/modules/dmq_usrloc/usrloc_sync.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/dmq_usrloc/usrloc_sync.c b/src/modules/dmq_usrloc/usrloc_sync.c index 9b966d5ae69..0a9917ce0a5 100644 --- a/src/modules/dmq_usrloc/usrloc_sync.c +++ b/src/modules/dmq_usrloc/usrloc_sync.c @@ -62,8 +62,6 @@ static int add_contact(str aor, ucontact_info_t* ci) return -1; } - dmq_ul.lock_udomain(_d, &aor); - LM_DBG("aor: %.*s\n", aor.len, aor.s); LM_DBG("ci->ruid: %.*s\n", ci->ruid.len, ci->ruid.s); LM_DBG("aorhash: %i\n", dmq_ul.get_aorhash(&aor)); @@ -72,6 +70,7 @@ static int add_contact(str aor, ucontact_info_t* ci) // Search by ruid, if possible res = dmq_ul.get_urecord_by_ruid(_d, dmq_ul.get_aorhash(&aor), &ci->ruid, &r, &c); if (res == 0) { + dmq_ul.lock_udomain(_d, &aor); LM_DBG("Found contact\n"); dmq_ul.update_ucontact(r, c, ci); LM_DBG("Release record\n"); @@ -81,6 +80,8 @@ static int add_contact(str aor, ucontact_info_t* ci) return 0; } } + + dmq_ul.lock_udomain(_d, &aor); res = dmq_ul.get_urecord(_d, &aor, &r); if (res < 0) { LM_ERR("failed to retrieve record from usrloc\n"); From 309873e14bc94f99cbb74cebf8c0302134f5f8b0 Mon Sep 17 00:00:00 2001 From: Julien Chavanton Date: Thu, 5 Jan 2017 09:40:56 -0500 Subject: [PATCH 2/2] dmq_usrloc: get_urecord_by_ruid returns with the lock if the record was found --- src/modules/dmq_usrloc/usrloc_sync.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/dmq_usrloc/usrloc_sync.c b/src/modules/dmq_usrloc/usrloc_sync.c index 0a9917ce0a5..5a11e82970d 100644 --- a/src/modules/dmq_usrloc/usrloc_sync.c +++ b/src/modules/dmq_usrloc/usrloc_sync.c @@ -70,7 +70,6 @@ static int add_contact(str aor, ucontact_info_t* ci) // Search by ruid, if possible res = dmq_ul.get_urecord_by_ruid(_d, dmq_ul.get_aorhash(&aor), &ci->ruid, &r, &c); if (res == 0) { - dmq_ul.lock_udomain(_d, &aor); LM_DBG("Found contact\n"); dmq_ul.update_ucontact(r, c, ci); LM_DBG("Release record\n");