[Tango-cs-bug-info] [tango-cs:bugs] #830 Deadlock between event subscription and callback

0 views
Skip to first unread message

tango-cs...@lists.sourceforge.net

unread,
Nov 21, 2016, 9:58:48 AM11/21/16
to Tango-cs...@lists.sf.net

[bugs:#830] Deadlock between event subscription and callback

Status: open
Created: Mon Nov 21, 2016 02:58 PM UTC by Vincent Michel
Last Updated: Mon Nov 21, 2016 02:58 PM UTC
Owner: nobody

I noticed that event subscriptions and event callbacks share a hidden lock, which can cause a deadlock in the following situation:

import time
import tango
import threading

CHANGE_EVENT = tango.EventType.CHANGE_EVENT

def callback(event):
    with monitor:
        print(event.attr_value.value)

monitor = threading.RLock()
with monitor:
    proxy = tango.DeviceProxy('sys/tg_test/1')
    eid1 = proxy.subscribe_event('double_scalar', CHANGE_EVENT, callback)
    time.sleep(1.)
    eid2 = proxy.subscribe_event('State', CHANGE_EVENT, callback)
    print('OK')
raw_input()

If an actual double_scalar event is generated during time.sleep, here's what happens:
- the callback thread acquires the hidden lock
- the callback thread waits for the monitor lock
- the main thread wakes up (end of sleep)
- the main thread runs subscribe_event
- the main thread waits for the hidden lock
- deadlock!

This is actually what happens in some devices, when the event callback tries to acquire the monitor lock (useful to prevent race condition between device callbacks and event callbacks).

Weirdly enough, I haven't been able to reproduce it during the first init_device. Instead, I had to run the INIT command to run init_device a second time and reliably generate the deadlock.

Tested with tango 9.2.2.


Sent from sourceforge.net because Tango-cs...@lists.sf.net is subscribed to https://sourceforge.net/p/tango-cs/bugs/

To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/tango-cs/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list.

message-footer.txt
Reply all
Reply to author
Forward
0 new messages