tango-controls / cppTango

Moved to gitlab
http://tango-controls.org
41 stars 34 forks source link

Subscribing twice to the same attribute raises a DevFailed in Tango 9 #227

Closed tango-controls-bot closed 7 years ago

tango-controls-bot commented 8 years ago

Subscribing twice to the same attribute raises an exception in Tango 9:

DevError[
    desc = Failed to connect to event channel for device tango://vinmic-t440p.maxiv.lu.se:10000/sys/tg_test/1
           Corrupted internal map: event callback already exists. Please report bug!
  origin = EventConsumer::connect_event()
  reason = API_NotificationServiceFailed
severity = ERR]

This happens even if the proxies and/or callbacks are different objects. The following example shows how to reproduce the bug:

>>> import PyTango
>>> d1 = PyTango.DeviceProxy('sys/tg_test/1')
>>> def f(arg): print arg.attr_value.value
...
>>> d1.subscribe_event('State', PyTango.EventType.CHANGE_EVENT, f)
RUNNING
1
>>> d2 = PyTango.DeviceProxy('sys/tg_test/1')
>>> def g(arg): print arg.attr_value.value
...
>>> d2.subscribe_event('State', PyTango.EventType.CHANGE_EVENT, g)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/vinmic/.virtualenvs/tango9/local/lib/python2.7/site-packages/PyTango/green.py", line 173, in greener
    ret = submit(fn, self, *args, **kwargs)
  File "/home/vinmic/.virtualenvs/tango9/local/lib/python2.7/site-packages/PyTango/green.py", line 83, in synch_submit
    return get_synch_executor().submit(fn, *args, **kwargs)
  File "/home/vinmic/.virtualenvs/tango9/local/lib/python2.7/site-packages/PyTango/green.py", line 75, in submit
    return fn(*args, **kwargs)
  File "/home/vinmic/.virtualenvs/tango9/local/lib/python2.7/site-packages/PyTango/device_proxy.py", line 853, in __DeviceProxy__subscribe_event
    event_id = self.__subscribe_event(attr_name, event_type, cb, filters, stateless, extract_as)
PyTango.EventSystemFailed: DevFailed[
DevError[
    desc = Failed to connect to event channel for device tango://vinmic-t440p.maxiv.lu.se:10000/sys/tg_test/1
           Corrupted internal map: event callback already exists. Please report bug!
  origin = EventConsumer::connect_event()
  reason = API_NotificationServiceFailed
severity = ERR]
]

In Tango 8, this last line would simply print RUNNING and return 2.

Reported by: vxgmichel

Original Ticket: tango-cs/bugs/780

tango-controls-bot commented 8 years ago

I am not able to reproduce this problem (two subscriptions to the same device, same attribute with different callback objects) neither with Tango 9.1 neither with the future 9.2 Therefore, I switch the Category to PyTango

Emmanuel

Original comment by: taurel

tango-controls-bot commented 8 years ago

Original comment by: taurel

tango-controls-bot commented 8 years ago

Hi, I had the same problem on my computer, using C++ API. But it happens only under certain circumstances. I am able to reproduce it in TangoBox after I disconnect TangoBox from the network (using the menu near the top-right corner of Ubuntu). Below, I am writing what I think was the cause of the problem. Coincidentally, I planned to submit a bug report today, but then I saw that it was probably fixed in svn yesterday by commit 29267.

The problem was in the connect_event function in event.cpp, where, in Tango 9.1.0, line 1771 sometimes changes local_callback_key. This is a problem, because the old name is used (line 1448) to check whether the event has been registered earlier, however, if it has been registered earlier, it is not found, because it was stored under the changed name. This leads to trying to add an already existing key to event_callback_map (line 1779) and this produces the exception.

Josef

Original comment by: jcibulka

tango-controls-bot commented 8 years ago

Hi Josef,

Good catch. It's true that in some cases the local_callback_key could be changed and if this happens, the bug will be there. When I have tried this morning with both Tango 9.1 and 9.2 I was not able to reproduce it because with 9.1 I was not in the case where the string is modified (using tango host env. variable with a host name which is an alias) and with Tango 9.2 as you noticed, the string is not modified and therefore the bug is not there anymore.

To keep the story short, I would say that this bug is at the C++ level and it is fixed for Tango 9.2

Cheers

Emmanuel

Original comment by: taurel

tango-controls-bot commented 8 years ago

Original comment by: tiagocoutinho