Segfault in read_attributes_asynch callback when attribute read times out
I have noticed that when using the read_attributes_asynch
method of a device proxy in the callback mode, if the attribute read takes longer than the device proxy the program will crash with a segfault, apparently when trying to extract the result of the read.
When reading the attribute directly with a synchronous call, or reading the attribute using the async polling method, we receive a timeout error as would be expected.
I'm not sure if this is a bug in pytango handling cppTango errors, or in cppTango itself. I can try and compile a C++ program to see if it has similar issues if it would be helpful.
I have a reproducible example at dustinlagoy/pytango-callback-segfault-issue>. With the included server and tango database running the client script yields output similar to the following:
PyTango 9.5.0 (9, 5, 0)
PyTango compiled with:
Python : 3.11.6
Numpy : 1.23.2
Tango : 9.5.0
Boost : 1.82.0
PyTango runtime is:
Python : 3.11.2
Numpy : 1.24.2
Tango : 9.5.0
PyTango running on:
...
1.0
server.bad error
wait
wait
wait
wait
wait
wait
wait
DevFailed[
DevError[
desc = TRANSIENT CORBA system exception: TRANSIENT_CallTimedout
origin = void Tango::DeviceProxy::read_attr_except(CORBA::Request_ptr, long int, Tango::DeviceProxy::read_attr_type) at (/src/cppTango/src/client/proxy_asyn.cpp:1822)
reason = API_CorbaException
severity = ERR]
DevError[
desc = Timeout (3000 mS) exceeded on device my/test/server
Attribute(s): bad
origin = void Tango::DeviceProxy::read_attr_except(CORBA::Request_ptr, long int, Tango::DeviceProxy::read_attr_type) at (/src/cppTango/src/client/proxy_asyn.cpp:1822)
reason = API_DeviceTimedOut
severity = ERR]
]
wait
wait
wait
wait
zsh: segmentation fault (core dumped) python ./client.py
Here the first two calls yield errors as expected but using the async callback causes the script to crash.
And here is a stack trace from GDB, which seems to point at some issue in callback.cpp:
#0 0x00007ffff67246ec in boost::python::api::object PyDeviceAttribute::convert_to_python<Tango::DeviceAttribute>(std::unique_ptr<std::vector<Tango::DeviceAttribute, std::allocator<Tango::DeviceAttribute> >, std::default_delete<std::vector<Tango::DeviceAttribute, std::allocator<Tango::DeviceAttribute> > > > const&, Tango::DeviceProxy&, PyTango::ExtractAs) ()
from /home/lagoyd/.pyenv/versions/3.11.2/lib/python3.11/site-packages/tango/_tango.so
#1 0x00007ffff67d920f in PyCallBackAutoDie::attr_read(Tango::AttrReadEvent*) ()
from /home/lagoyd/.pyenv/versions/3.11.2/lib/python3.11/site-packages/tango/_tango.so
#2 0x00007ffff5f03e72 in Tango::Connection::Cb_ReadAttr_Request(CORBA::Request*, Tango::CallBack*) ()
from /home/lagoyd/.pyenv/versions/3.11.2/lib/python3.11/site-packages/tango/../pytango.libs/libtango-167aeef5.so.9.5.0
#3 0x00007ffff5ee7c21 in Tango::ApiUtil::get_asynch_replies(long) ()
from /home/lagoyd/.pyenv/versions/3.11.2/lib/python3.11/site-packages/tango/../pytango.libs/libtango-167aeef5.so.9.5.0
#4 0x00007ffff5ef560c in Tango::CallBackThread::run_undetached(void*) ()
from /home/lagoyd/.pyenv/versions/3.11.2/lib/python3.11/site-packages/tango/../pytango.libs/libtango-167aeef5.so.9.5.0
#5 0x00007ffff7faa225 in omni_thread_wrapper ()
from /home/lagoyd/.pyenv/versions/3.11.2/lib/python3.11/site-packages/tango/../pytango.libs/libomnithread-d7d1252e.so.4.3
#6 0x00007ffff7494ac3 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#7 0x00007ffff7526850 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81