I noticed that sql_query does not (anymore) work when called from event route:
event_route [tcp:closed] { # Handle TCP connection close
# Delete possible leftover registration if ($conid) sql_query("sip_proxy_cache", "DELETE FROM location WHERE server_id=0 AND connection_id=$conid", "result"); }
The query produces errors:
2024-05-07T11:30:14.785915+03:00 siika /usr/bin/sip-proxy[2848078]: CRITICAL: sqlops [sqlops.c:213]: sql_check_connection(): no database handle with reconnect disabled 2024-05-07T11:30:14.785978+03:00 siika /usr/bin/sip-proxy[2848078]: ERROR: sqlops [sqlops.c:232]: sql_query(): invalid connection to database 2024-05-07T11:30:14.786013+03:00 siika /usr/bin/sip-proxy[2848078]: ERROR: sqlops [sqlops.c:237]: sql_query(): with query [DELETE FROM location WHERE server_id=0 AND connection_id=7]
I added the last debug message in order to find out where the error comes from.
The same query works fine when executed from regular route.
Any ideas why the query fails from event_route?
-- Juha
Juha Heinanen via sr-users writes:
I noticed that sql_query does not (anymore) work when called from event route:
I created bug issue https://github.com/kamailio/kamailio/issues/3843 about this to GitHub, since it really looks like a bug, because the same code has worked fine in some earlier K release.
-- Juha
On 07.05.24 11:15, Juha Heinanen via sr-users wrote:
Juha Heinanen via sr-users writes:
I noticed that sql_query does not (anymore) work when called from event route:
I created bug issue https://github.com/kamailio/kamailio/issues/3843 about this to GitHub, since it really looks like a bug, because the same code has worked fine in some earlier K release.
I posted on the tracker as well, but for sake of completing the discussion here for mailing list archive ...
Connection close event is executed from TCP main process, which likely has no SQL connection open. Till some point in the past, connection close event was triggered from a few places (from tcp worker processes), but actually it was not done for all cases when the connections were closed, some of these events missing (there are situations when only tcp main process close the connections). Now, I would strongly advise doing anything time expensive in the TCP main process, it was designed only as tcp connections manager, so in this case, I would rather delegate the sql query to an async worker (via async module or via mqueue+rtimer).
Cheers, Daniel
correction, see inline ...
On 07.05.24 12:34, Daniel-Constantin Mierla wrote:
On 07.05.24 11:15, Juha Heinanen via sr-users wrote:
Juha Heinanen via sr-users writes:
I noticed that sql_query does not (anymore) work when called from event route:
I created bug issue https://github.com/kamailio/kamailio/issues/3843 about this to GitHub, since it really looks like a bug, because the same code has worked fine in some earlier K release.
I posted on the tracker as well, but for sake of completing the discussion here for mailing list archive ...
Connection close event is executed from TCP main process, which likely has no SQL connection open. Till some point in the past, connection close event was triggered from a few places (from tcp worker processes), but actually it was not done for all cases when the connections were closed, some of these events missing (there are situations when only tcp main process close the connections). Now, I would strongly advise
^^^ advise *against* doing ...
doing anything time expensive in the TCP main process, it was designed only as tcp connections manager, so in this case, I would rather delegate the sql query to an async worker (via async module or via mqueue+rtimer).
Cheers, Daniel
-- Daniel-Constantin Mierla (@ asipto.com) twitter.com/miconda -- linkedin.com/in/miconda Kamailio Consultancy, Training and Development Services -- asipto.com