]> git.ipfire.org Git - thirdparty/asterisk.git/commit
res_odbc.c: Allow concurrent access to request odbc connections
authorMatthew Fredrickson <matt@fredricknet.net>
Thu, 30 Nov 2023 17:57:53 +0000 (11:57 -0600)
committerMatthew Fredrickson <matt@fredricknet.net>
Wed, 6 Dec 2023 21:19:15 +0000 (21:19 +0000)
commit058ead0ea5e64496cc56ce809aca0a31aa7ea77b
treeffecd0233d04a74070fffea67df7288718690977
parent0ed2e8200a315573143160ff7584274e694d8b6e
res_odbc.c: Allow concurrent access to request odbc connections

There are valid scenarios where res_odbc's connection pool might have some dead
or stuck connections while others are healthy (imagine network
elements/firewalls/routers silently timing out connections to a single DB and a
single IP address, or a heterogeneous connection pool connected to potentially
multiple IPs/instances of a replicated DB using a DNS front end for load
balancing and one replica fails).

In order to time out those unhealthy connections without blocking access to
other parts of Asterisk that may attempt access to the connection pool, it would
be beneficial to not lock/block access around the entire pool in
_ast_odbc_request_obj2 while doing potentially blocking operations on connection
pool objects such as the connection_dead() test, odbc_obj_connect(), or by
dereferencing a struct odbc_obj for the last time and triggering a
odbc_obj_disconnect().

This would facilitate much quicker and concurrent timeout of dead connections
via the connection_dead() test, which could block potentially for a long period
of time depending on odbc.ini or other odbc connector specific timeout settings.

This also would make rapid failover (in the clustered DB scenario) much quicker.

This patch changes the locking in _ast_odbc_request_obj2() to not lock around
odbc_obj_connect(), _disconnect(), and connection_dead(), while continuing to
lock around truly shared, non-immutable state like the connection_cnt member and
the connections list on struct odbc_class.

Fixes: #465
res/res_odbc.c