kamailio / kamailio

Kamailio - The Open Source SIP Server for large VoIP and real-time communication platforms -
https://www.kamailio.org
Other
2.27k stars 948 forks source link

[Websocket] websocket:closed event sometimes is not fired #3950

Open bundasmanu opened 1 month ago

bundasmanu commented 1 month ago

Description

After carrying out some load tests using the Websocket module, I noticed that sometimes the websocket:closed event is not triggered.

This problem seems to be particularly noticeable when the load is high and simultaneous. Example: 1000 records simultaneously.

In the tests carried out, I realized that the number of times the event is not triggered is small, in the order of [1-10]/1000.

I check that when I do a ws.dump I don't have any active connections, and I confirm that they are all effectively cleaned (netstat -ano | grep 8061). However, the event is not triggered for some connections. I can see this in the logs, and also when i display the content of an hash table, i'm dropping key inside websocket:closed event.

Troubleshooting

The troubleshooting was simplistic, i.e. I ran the same test n times, and validated that the event was triggered for all connections, the number of ws connections listed by Kamailio, and the open connections.

Reproduction

To reproduce, we can use any mechanism that emulates the use of the Websocket module.

For example, I used the sipexer tool to create wss connections with Kamailio, forcing simultaneous registrations.

Example command: sipexer -cb -mt register -ex 60 -au <user> -ap <pass> -fuser example -fd mydomain -wso https://10.0.0.12:10000 -ruri sip:kamailio -su wss://kamailio:8061

Kamailio TLS listener:

listen=tls:10.0.0.12:8061 advertise PUBLIC_IP

Websocket module:

loadmodule "websocket.so"
tcp_accept_no_cl=yes
    event_route[websocket:closed] {
        xlog("L_NOTICE", "WebSocket connection closed $proto:$si:$sp\n");
       <I  also delete where a htable key>
    }

Debugging Data

[root@ ~]$ kamcmd ws.dump
{
    connections: {
    }
    info: {
        wscounter: 0
        truncated: no
    }
}
[root@ ~]$ netstat -ano | grep 8061
tcp        0      0 10.0.0.12:8061          0.0.0.0:*               LISTEN      off (0.00/0/0)

[root ~]$ kamcmd htable.dump wsauth | grep "name" | wc -l
3

[root ~]$ cat /var/log/kamailio.log | grep "WebSocket connection closed" | wc -l
997

[root ~]$ cat /var/log/kamailio.log | grep "ERR" | grep "WAR" | wc -l
0

Log Messages

Nothing relevant.

SIP Traffic

Nothing relevant here, the SIP Flow is OK.

Additional Information

version: kamailio 5.6.4 (x86_64/linux) a004cf-dirty
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, 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_BLOCKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: a004cf -dirty
compiled on 23:17:27 Jun  7 2024 with gcc 4.8.5
CentOS Linux release 7.9.2009 (Core)
github-actions[bot] commented 21 hours ago

This issue is stale because it has been open 6 weeks with no activity. Remove stale label or comment or this will be closed in 2 weeks.