[SR-Users] uac_req_send() multi-process synchronization problem

Henning Westerholt hw at gilawa.com
Thu Dec 8 09:57:12 CET 2022


Thanks for the update, great that you found a solution and reported back to the list.

Cheers,

Henning

--
Henning Westerholt – https://skalatan.de/blog/
Kamailio services – https://gilawa.com<https://gilawa.com/>

From: riffs at sina.cn <riffs at sina.cn>
Sent: Friday, December 2, 2022 7:40 AM
To: Henning Westerholt <hw at gilawa.com>
Cc: sr-users <sr-users at lists.kamailio.org>
Subject: Re: RE: [SR-Users] uac_req_send() multi-process synchronization problem


Thank you for your reply very much,Because this is my first mail list. Don't know need keep the list in CC. I'm sorry.

I foun a paramter from cookbooks. It feels like setting the tcp_accept_unique to 1 avoids this problem

tcp_accept_unique

If set to 1, reject duplicate connections coming from same source IP and port.

Default set to 0.

tcp_accept_unique = 1
tcp_accept_unique role in the source code:
        if(tcp_accept_unique) {
            if(tcpconn_exists(0, &tcpconn->rcv.dst_ip, tcpconn->rcv.dst_port,
                        &tcpconn->rcv.src_ip, tcpconn->rcv.src_port)) {
                LM_ERR("duplicated connection by local and remote addresses\n");
                _tcpconn_free(tcpconn);
                tcp_safe_close(new_sock);
                return 1; /* success, because the accept was successful */
            }
        }

________________________________
riffs at sina.cn<mailto:riffs at sina.cn>

From: Henning Westerholt<mailto:hw at gilawa.com>
Date: 2022-12-01 18:23
To: riffs at sina.cn<mailto:riffs at sina.cn>
CC: sr-users at lists.kamailio.org<mailto:sr-users at lists.kamailio.org>
Subject: RE: Re: [SR-Users] uac_req_send() multi-process synchronization problem
Hello,

please keep the list in CC.

Not sure what you mean by multi-process safe. The functions are safe to use in a kamailio multi-process context, relevant sections should be protected by internal locks etc..

Regarding query location manually by SQL client, its better to use the provided functions from the usrloc/registrar module instead.

Cheers,

Henning

--
Henning Westerholt – https://skalatan.de/blog/
Kamailio services – https://gilawa.com<https://gilawa.com/>

From: riffs at sina.cn<mailto:riffs at sina.cn> <riffs at sina.cn<mailto:riffs at sina.cn>>
Sent: Thursday, December 1, 2022 10:47 AM
To: Henning Westerholt <hw at gilawa.com<mailto:hw at gilawa.com>>
Subject: Re: Re: [SR-Users] uac_req_send() multi-process synchronization problem


To confirm that. Are reg_fetch_contacts and unregister_ruid multi-process safe?


________________________________
riffs at sina.cn<mailto:riffs at sina.cn>

From: riffs at sina.cn<mailto:riffs at sina.cn>
Date: 2022-12-01 16:35
To: Henning Westerholt<mailto:hw at gilawa.com>
Subject: Re: RE: [SR-Users] uac_req_send() multi-process synchronization problem
Hello
Thank you for your reply very much.  My LOCATION is stored in the MYSQL database, and I also set the event_callback parameter of TCPOPS.
modparam("tcpops", "event_callback", "ksr_tcpops_event")

At the same time.I also deleted the contact inside the function
function ksr_tcpops_event(evname)
    local tcpconnid = KSR.pv.get("$conid") or "0"
       if (evname == "tcp:reset" or evname == "tcp:closed") and (tonumber(tcpconnid) ~= 0)  then
        local sql = string.format("select * from location where tcpconnid=%s", tcpconnid)
        local count, rows = execute_select(sql)
        if count > 0 then
             KSR.registrar.unregister_ruid("location", rows[1].contact, rows[1].ruid)
        end
    end
    return 1
end
When I use use_req_send(), I use the following sql statement to query location
string.format("select * from location where username='%s'", reciever)
I think because the query sql is executed before the execution of unregister_ruid completes, the location of user A can still be queried.
If unregister_ruid and reg_fetch_contacts are multi-process safe. I use reg_fetch_contacts query location to avoid this problem. Is that so?
thanks very much



________________________________
riffs at sina.cn<mailto:riffs at sina.cn>

From: Henning Westerholt<mailto:hw at gilawa.com>
Date: 2022-11-30 18:18
To: Kamailio (SER) - Users Mailing List<mailto:sr-users at lists.kamailio.org>
CC: 刘建峰<mailto:riffs at sina.cn>
Subject: RE: [SR-Users] uac_req_send() multi-process synchronization problem
Hello,

not sure if I fully understand the problem. But regarding another user is registered with the same IP address as a previous user, there are several mitigations.

To give two options: you could choose a really short re-registration time, you could use TCP and when you lose the connection you delete the contact.

Cheers,

Henning

--
Henning Westerholt – https://skalatan.de/blog/
Kamailio services – https://gilawa.com<https://gilawa.com/>

From: sr-users <sr-users-bounces at lists.kamailio.org<mailto:sr-users-bounces at lists.kamailio.org>> On Behalf Of ???
Sent: Wednesday, November 30, 2022 2:57 AM
To: sr-users at lists.kamailio.org<mailto:sr-users at lists.kamailio.org>
Subject: [SR-Users] uac_req_send() multi-process synchronization problem

When I use uac_req_send() to send a MESSAGE to the client. Will the following occur? The result of the message sent to user A is that B has received it. From the logs, the address of user A in the location table is the same as the IP address and port of user B, and the information of user A in the location table is not deleted in time. I took the address of user A directly from the location table without using KSR.registrar.reg_fetch_contacts(). If I use KSR.registrar.reg_fetch_contacts() can this be avoided. This is a multi-process synchronization problem, after user A registers, the IP port information in the address is 172.16.22.222:12345, and then user A disconnects the link because of some abnormal conditions, but it is not normal to cancel the registration, the socket link has failed, but it has not had time to delete the location, at this time user B registers, whether will it get the same IP port information as user A 172.16.22.222 : 12345, if possible? User A's location still exists, Using KSR.registrar.reg_fetch_contacts() TO query user A's location, and then using uac_req_send() to send a message to user A, User B will receive the MESSAGE. Whether this problem occurs?

从 Windows 版邮件<https://go.microsoft.com/fwlink/?LinkId=550986>发送

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20221208/54e6b2bd/attachment.htm>


More information about the sr-users mailing list