]> 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:13 +0000 (21:19 +0000)
commitbfac3945f6402fa7f9c539651e5c107183aaa06a
tree05a871af05aed878bf0831d5eb566df146312502
parenta2f0d99d9d6458a5bee73aeefb44bc0ae99d81df
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