simultaneous events corrupt event_data

Hi,

during my stress tests with sardana https://github.com/sardana-org/sardana/issues/447 I found that when I emits EventType.CHANGE_EVENT events of DevEncoded attribute:

import PyTango
from taurus.core.util.codecs import CodecFactory

def cb(event_data):
    if event_data.err:
        print "event error"
        return
    w = CodecFactory().decode(event_data.attr_value.value)

door = PyTango.DeviceProxy("door/stretch-jk/1")

while True:
    id_ = door.subscribe_event("RecordData", PyTango.EventType.CHANGE_EVENT, cb, stateless=True)
    door.unsubscribe_event(id_)

for a very few cases event_data is changed by pytango/tango. I run test with PyTango 9.2.1 and 9.2.0 (tango 8.2.5a) on stretch and jessie getting similar issues. I've not manged to check it with the develop branch of PyTango because of https://github.com/tango-controls/pytango/issues/144 Error appears when I run simultaneously many clients subscribed to the same attribute.

In order to check it I added print-outs in

  1. void __set_value(...) in val_real of ext/server/attribute.cpp indirectly called by read_RecordData
  2. update_value_as_string<Tango::DEV_ENCODED>(...) in r_ch_ptr of ext/device_attribute.cpp called during creating event_data which is read by callback method.

In the most cases for the corresponding calls the data were equal but I get also cases where a few bytes of long encoded data records of r_ch_ptr were overwritten at the end or at the begining e.g. a)

val_real[-10:] =  '\xdc\x91N\x14$\x11=\x914\x00'
r_ch_ptr[-10:] =  '\xdc\x91N\x90-\x00\x00\x00\x00\x00'

b)

val_real[-10:] =  '\xb9"\x9c(H&C\xf0\x89\x80'
r_ch_ptr[-10:] =  '\xb9"\x9c(H&C\x80-\x00'

c)

val_real[:20] = 'BZh91AY&SYy\x18\x1ci\x00C\xc8\x7f\xff\xff'
r_ch_ptr[:20] = '\xce\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1ci\x00C\xc8\x7f\xff\xff'

For 9.2.0 I get also the cases where whole long data_event value was filled with '\x00' characters. In my test case since the data is pickled during decoding data I get IOError: invalid data stream but I can imaging that for other cases user may even not notice that the data is corrupted.

Therefore I would like to ask if someone account a similar problem.

Best regards, Jan

Edited by Yury Matveev