[bug] Python samples "registration.py" race-condition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I would like to report a bug in pjsip-apps/src/python/samples/registration.py:

There is a race-condition when waiting for the registration to finish.
The reason is, that the semaphore is created in wait, which may be too
late.

Demo:
add "time.sleep(2)" between acc.set_callback(acc_cb) and acc_cb.wait():

...
try:
    ...
    acc_cb = MyAccountCallback(acc)
    acc.set_callback(acc_cb)
    time.sleep(2)
    acc_cb.wait()
...

Solution: Create the semaphore before, e.g. in MyAccountCallback.__init__.

I've attached a patch.


thanks,
Roland

--- pjsip-apps/src/python/samples/registration.py	2016-12-08 09:47:08.219750687 +0100
+++ pjsip-apps/src/python/samples/registration.py	2016-12-18 01:29:52.935997398 +0100
@@ -28,13 +28,12 @@
     print str,
 
 class MyAccountCallback(pj.AccountCallback):
-    sem = None
 
     def __init__(self, account):
         pj.AccountCallback.__init__(self, account)
+        self.sem = threading.Semaphore(0)
 
     def wait(self):
-        self.sem = threading.Semaphore(0)
         self.sem.acquire()
 
     def on_reg_state(self):
_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux