[SR-Users] Using lock() correctly
Daniel-Constantin Mierla
miconda at gmail.com
Mon Jul 3 13:39:22 CEST 2017
I don't get to which log messages are you referring not being printed
correctly. Maybe you can add numbers in front of each message and then
list what's the order you expect.
Cheers,
Daniel
On 03.07.17 12:58, Sebastian Damm wrote:
> Okay, I understand. But even after processing the second packet
> finished, there are still messages coming from the lua script
> processing the first packet. And those log lines come from within the
> lock.
>
> I would expect that the log lines look like that:
>
> Jun 28 13:27:04 busch /usr/sbin/kamailio[18836]: INFO: <script>: Got
> new packet INVITE: 172.20.21.247 => 172.20.21.4
> Jun 28 13:27:04 busch /usr/sbin/kamailio[18836]: INFO: <script>:
> Obtained lock, calling lua...
> Jun 28 13:27:04 busch /usr/sbin/kamailio[18836]: INFO: app_lua
> [app_lua_sr.c:98]: lua_sr_log(): some logging
> Jun 28 13:27:04 busch /usr/sbin/kamailio[18837]: INFO: <script>: Got
> new packet INVITE: 172.20.21.4 => 172.20.21.247 - Reply Code 407
> Jun 28 13:27:04 busch /usr/sbin/kamailio[18836]: INFO: app_lua
> [app_lua_sr.c:98]: lua_sr_log(): some more logging
> Jun 28 13:27:04 busch /usr/sbin/kamailio[18836]: INFO: app_lua
> [app_lua_sr.c:98]: lua_sr_log(): lua finished
> Jun 28 13:27:04 busch /usr/sbin/kamailio[18836]: INFO: <script>: Lua
> finished, released lock...
> Jun 28 13:27:04 busch /usr/sbin/kamailio[18837]: INFO: <script>:
> Obtained lock, calling lua...
> Jun 28 13:27:04 busch /usr/sbin/kamailio[18837]: INFO: <script>: Lua
> finished, released lock...
>
> While I agree that the last line for process 18336 could appear later,
> the other lines should appear before 18337 can obtain the lock.
>
> Best Regards,
> Sebastian
>
> On Mon, Jul 3, 2017 at 12:20 PM, Daniel-Constantin Mierla
> <miconda at gmail.com> wrote:
>> Hello,
>>
>> your log message saying that the lock is released is printed after
>> unlock(). When unlock() is executed, the process can lose the CPU and
>> the other process enters the lock() and does its stuff, can even
>> overtake the first process and printing that it released the lock,
>> nothing is guaranteed outside of lock()/unlock(), it is OS scheduler
>> deciding what to do.
>>
>> Cheers,
>> Daniel
>>
>> On 03.07.17 12:12, Sebastian Damm wrote:
>>> Hi Daniel,
>>>
>>> thanks for the reply.
>>>
>>> On Mon, Jul 3, 2017 at 11:57 AM, Daniel-Constantin Mierla
>>> <miconda at gmail.com> wrote:
>>>> the last log message is outside of the lock()/unlock(), so it can
>>>> printed whenever the OS decides to allocate CPU for it. You should move
>>>> it inside the locked block, but then also be sure the syslog is not
>>>> asynchronous, because then it can be syslog changing the order.
>>> Well but shouldn't it be printed only after the lua block was
>>> executed? It still looks like the second packet didn't wait for the
>>> first packet to release the lock.
>>>
>>> My problem is, that I'm writing entries into a hash table if some
>>> conditions of an INVITE matches. But the 100 Trying often comes in
>>> before the processing of the INVITE is finished. So it is dropped
>>> because the reference in the hash table is missing. That's why I
>>> wanted to have locking. The second process shouldn't print out
>>> "Obtained lock" until the other one has released the lock. And since
>>> the first process is still within it's lua logic, I'm pretty sure the
>>> lock has not been released.
>>>
>>>> Also, unrelated, you should not use drop, unless you want to drop the
>>>> response and not sending it out. For request is not making any
>>>> difference compared with exit.
>>> Actually, I want to drop every packet on the system, because it is
>>> only a sniffer that does something with the sniffed packets.
>>>
>>> Best Regards,
>>> Sebastian
>>>
>>> _______________________________________________
>>> Kamailio (SER) - Users Mailing List
>>> sr-users at lists.kamailio.org
>>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>> --
>> Daniel-Constantin Mierla
>> www.twitter.com/miconda -- www.linkedin.com/in/miconda
>> Kamailio Advanced Training - www.asipto.com
>> Kamailio World Conference - www.kamailioworld.com
>>
> _______________________________________________
> Kamailio (SER) - Users Mailing List
> sr-users at lists.kamailio.org
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
--
Daniel-Constantin Mierla
www.twitter.com/miconda -- www.linkedin.com/in/miconda
Kamailio Advanced Training - www.asipto.com
Kamailio World Conference - www.kamailioworld.com
More information about the sr-users
mailing list