diff options
author | Tilghman Lesher <tilghman@meg.abyt.es> | 2011-02-14 20:18:02 +0000 |
---|---|---|
committer | Tilghman Lesher <tilghman@meg.abyt.es> | 2011-02-14 20:18:02 +0000 |
commit | 5c49abfcf3fd36957eef8e38a179fdba5e8a6c8d (patch) | |
tree | 67adfa476a3fd1ce40f29e26c74f383a57999e42 /res | |
parent | c0e33b03c35b9ef27aea6c5716a5e44f0e1636e7 (diff) |
Merged revisions 307793 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
................
r307793 | tilghman | 2011-02-14 14:16:55 -0600 (Mon, 14 Feb 2011) | 15 lines
Merged revisions 307792 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.6.2
........
r307792 | tilghman | 2011-02-14 14:10:28 -0600 (Mon, 14 Feb 2011) | 8 lines
Increment usage count at first reference, to avoid a race condition with many threads creating connections all at once.
(issue #18156)
Reported by: asgaroth
Patches:
20110214__issue18156.diff.txt uploaded by tilghman (license 14)
Tested by: tilghman
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@307795 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res')
-rw-r--r-- | res/res_odbc.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/res/res_odbc.c b/res/res_odbc.c index 84d7284bb..1af8bbafd 100644 --- a/res/res_odbc.c +++ b/res/res_odbc.c @@ -1218,13 +1218,14 @@ struct odbc_obj *_ast_odbc_request_obj2(const char *name, struct ast_flags flags if (obj) { ast_assert(ao2_ref(obj, 0) > 1); } - if (!obj && (class->count < class->limit) && + if (!obj && (ast_atomic_fetchadd_int(&class->count, +1) < class->limit) && (time(NULL) > class->last_negative_connect.tv_sec + class->negative_connection_cache.tv_sec)) { obj = ao2_alloc(sizeof(*obj), odbc_obj_destructor); if (!obj) { class->count--; ao2_ref(class, -1); ast_debug(3, "Unable to allocate object\n"); + ast_atomic_fetchadd_int(&class->count, -1); return NULL; } ast_assert(ao2_ref(obj, 0) == 1); @@ -1235,14 +1236,18 @@ struct odbc_obj *_ast_odbc_request_obj2(const char *name, struct ast_flags flags if (odbc_obj_connect(obj) == ODBC_FAIL) { ast_log(LOG_WARNING, "Failed to connect to %s\n", name); ao2_ref(obj, -1); - ast_assert(ao2_ref(class, 0) > 0); obj = NULL; + ast_assert(ao2_ref(class, 0) > 0); + ast_atomic_fetchadd_int(&class->count, -1); } else { obj->used = 1; ao2_link(obj->parent->obj_container, obj); - ast_atomic_fetchadd_int(&obj->parent->count, +1); } } else { + /* If construction fails due to the limit (or negative timecache), reverse our increment. */ + if (!obj) { + ast_atomic_fetchadd_int(&class->count, -1); + } /* Object is not constructed, so delete outstanding reference to class. */ ao2_ref(class, -1); class = NULL; |