### Description
Kamailio crashes while querying for unexpired contacts in a location table while it is saving contacts to db.
Seems to be a regression, since this didn't happened with Kamailio 4.4.
#### Reproduction
Constantly flush many locations and simultaneously get location statistics from `usrloc` module via `kamcmd ul.db_users`:
```sh
shell1 % while kamcmd ul.flush ; do : ; done
```
```sh
shell2 % curl -H content-type:\ application/json -s -d '{"jsonrpc":"2.0", "method":"ul.db_contacts", "params": ["location"]}' localhost:5060/JSONRPC
```
#### Debugging Data
```
#0 0x00007f600e3345ad in ul_rpc_db_contacts (rpc=0x7f6004f8b960 <func_param>, ctx=0x7f6004f8b8e0 <_jsonrpc_ctx>) at ul_rpc.c:774
#1 0x00007f6004d6c15c in jsonrpc_dispatch (msg=0x7ffc7fc4e250, s1=0x0, s2=0x0) at jsonrpcs_mod.c:1251
#2 0x000055c674d60eb9 in do_action (h=0x7ffc7fc4e170, a=0x7f6012607828, msg=0x7ffc7fc4e250) at core/action.c:1054
#3 0x000055c674d6ea4d in run_actions (h=0x7ffc7fc4e170, a=0x7f6012607828, msg=0x7ffc7fc4e250) at core/action.c:1552
#4 0x000055c674d60e25 in do_action (h=0x7ffc7fc4e170, a=0x7f6012607ac8, msg=0x7ffc7fc4e250) at core/action.c:1045
#5 0x000055c674d6ea4d in run_actions (h=0x7ffc7fc4e170, a=0x7f6012600b28, msg=0x7ffc7fc4e250) at core/action.c:1552
#6 0x000055c674d60e25 in do_action (h=0x7ffc7fc4e170, a=0x7f6012607d00, msg=0x7ffc7fc4e250) at core/action.c:1045
#7 0x000055c674d6ea4d in run_actions (h=0x7ffc7fc4e170, a=0x7f60125fecf8, msg=0x7ffc7fc4e250) at core/action.c:1552
#8 0x00007f6004f913b4 in xhttp_process_request (orig_msg=0x7f6012622410, new_buf=0x7f6012638ad0 "POST /JSONRPC HTTP/1.1\r\nVia: SIP/2.0/TCP 127.0.0.1:58590\r\nHost: localhost:5060\r\nUser-Agent: curl/7.52.1\r\nAccept: */*\r\nContent-Length: 67\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n{\"jsonrpc\": \"2.0\", \"method\":\"ul.db_contacts\",\"params\":[\"location\"]}", new_len=256) at xhttp_mod.c:282
#9 0x00007f6004f9253b in xhttp_handler (msg=0x7f6012622410) at xhttp_mod.c:357
#10 0x000055c674e4be83 in nonsip_msg_run_hooks (msg=0x7f6012622410) at core/nonsip_hooks.c:111
#11 0x000055c674e944d7 in receive_msg (buf=0x7f5feac686a8 "POST /JSONRPC HTTP/1.1\r\nHost: localhost:5060\r\nUser-Agent: curl/7.52.1\r\nAccept: */*\r\nContent-Length: 67\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n{\"jsonrpc\": \"2.0\", \"method\":\"ul.db_contacts\",\"params\":[\"location\"]}", len=222, rcv_info=0x7f5feac683c8) at core/receive.c:202
#12 0x000055c674f2e43c in receive_tcp_msg (tcpbuf=0x7f5feac686a8 "POST /JSONRPC HTTP/1.1\r\nHost: localhost:5060\r\nUser-Agent: curl/7.52.1\r\nAccept: */*\r\nContent-Length: 67\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n{\"jsonrpc\": \"2.0\", \"method\":\"ul.db_contacts\",\"params\":[\"location\"]}", len=222, rcv_info=0x7f5feac683c8, con=0x7f5feac683b0) at core/tcp_read.c:1263
#13 0x000055c674f30a70 in tcp_read_req (con=0x7f5feac683b0, bytes_read=0x7ffc7fc4ee68, read_flags=0x7ffc7fc4ee6c) at core/tcp_read.c:1478
#14 0x000055c674f339bb in handle_io (fm=0x7f60126506b0, events=1, idx=-1) at core/tcp_read.c:1652
#15 0x000055c674f23d9b in io_wait_loop_epoll (h=0x55c6753e0fa0 <io_w>, t=2, repeat=0) at core/io_wait.h:1065
#16 0x000055c674f359b0 in tcp_receive_loop (unix_sock=54) at core/tcp_read.c:1822
#17 0x000055c674e14095 in tcp_init_children () at core/tcp_main.c:4802
#18 0x000055c674d216e1 in main_loop () at main.c:1713
#19 0x000055c674d286a9 in main (argc=13, argv=0x7ffc7fc4f4f8) at main.c:2642
```
#### Log Messages
```
ERROR: usrloc [urecord.c:431]: wb_timer(): updating contact in db failed (aor: 1234(a)example.com)
ERROR: db_mysql [km_dbase.c:127]: db_mysql_submit_query(): driver error on query: Commands out of sync; you can't run this command now (2014)
ERROR: <core> [db_query.c:339]: db_do_update(): error while submitting query
ERROR: usrloc [ucontact.c:1378]: db_update_ucontact_instance(): updating database failed
```
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
```
version: kamailio 5.0.7 (x86_64/linux)
flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown
compiled with gcc 6.3.0
```
* **Operating System**:
```
Debian 9.5
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/1900
### Description
On our setup with Kamailio 5.2.1 with users connected via TLS. i see frequently TCP/TLS sessions remain in CLOSE_WAIT:
netstat -ntp |grep CLOSE
tcp 238 0 172.17.217.10:5061 xxx.xxx.xxx.218:52613 CLOSE_WAIT 117912/kamailio
tcp 4681 0 172.17.217.10:5061 xxx.xxx.xxx.125:8892 CLOSE_WAIT 117912/kamailio
In tcpdump i see, that the client send a TCP FIN,ACK and and the OS which is hosting the Kamailio send TCP ACK. But Kamailio is not closing. So the session remain in CLOSE_WAIT for a long time (over a hour)
We also have configured:
tcp_connection_lifetime=65
modparam("tls", "connection_timeout", 63)
Which should finally close after 65 second. But no effect.
### Troubleshooting
#### Reproduction
Register SIP clients via TLS, and then let the client close the TCP session ia TCP FIN,ACK
* **Operating System**:
Debian GNU/Linux 9
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/1881
<!--
Kamailio Project uses GitHub Issues only for bugs in the code or feature requests. Please use this template only for bug reports.
If you have questions about using Kamailio or related to its configuration file, ask on sr-users mailing list:
* http://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
If you have questions about developing extensions to Kamailio or its existing C code, ask on sr-dev mailing list:
* http://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
Please try to fill this template as much as possible for any issue. It helps the developers to troubleshoot the issue.
If there is no content to be filled in a section, the entire section can be removed.
You can delete the comments from the template sections when filling.
You can delete next line and everything above before submitting (it is a comment).
-->
### Description
<!--
Explain what you did, what you expected to happen, and what actually happened.
-->
### Troubleshooting
#### Reproduction
<!--
If the issue can be reproduced, describe how it can be done.
-->
[root@kamailio-665b74f766-sv4mx /]# kamcmd
ERROR: connect_unix_sock: connect(/var/run/kamailio//kamailio_ctl): No such file or directory [2]
#### Debugging Data
<!--
If you got a core dump, use gdb to extract troubleshooting data - full backtrace,
local variables and the list of the code at the issue location.
gdb /path/to/kamailio /path/to/corefile
bt full
info locals
list
If you are familiar with gdb, feel free to attach more of what you consider to
be relevant.
-->
```
[root@kamailio-665b74f766-sv4mx /]# kamcmd
ERROR: connect_unix_sock: connect(/var/run/kamailio//kamailio_ctl): No such file or directory [2]
```
#### Log Messages
[root@kamailio-665b74f766-sv4mx /]# kamcmd
ERROR: connect_unix_sock: connect(/var/run/kamailio//kamailio_ctl): No such file or directory [2]
<!--
Check the syslog file and if there are relevant log messages printed by Kamailio, add them next, or attach to issue, or provide a link to download them (e.g., to a pastebin site).
-->
```
(paste your log messages here)
```
#### SIP Traffic
<!--
If the issue is exposed by processing specific SIP messages, grab them with ngrep or save in a pcap file, then add them next, or attach to issue, or provide a link to download them (e.g., to a pastebin site).
-->
```
(paste your sip traffic here)
```
### Possible Solutions
<!--
If you found a solution or workaround for the issue, describe it. Ideally, provide a pull request with a fix.
-->
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
```
(paste your output here)
```
* **Operating System**:
<!--
Details about the operating system, the type: Linux (e.g.,: Debian 8.4, Ubuntu 16.04, CentOS 7.1, ...), MacOS, xBSD, Solaris, ...;
Kernel details (output of `uname -a`)
-->
```
(paste your output here)
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/1909