mdavidsaver / pvxs

PVA protocol client/server library and utilities.
https://mdavidsaver.github.io/pvxs/
Other
19 stars 25 forks source link

Seg fault if `PVXS_QSRV_ENABLE` not set #50

Closed coretl closed 12 months ago

coretl commented 1 year ago

Describe the bug If PVXS_QSRV_ENABLE env variable is not set, then in some situations the IOC seg faults on exit

To Reproduce Steps to reproduce the behavior:

  1. Save code from #49 into file
  2. Comment out the env variable set
  3. Run it
  4. Ctrl-D
  5. See it seg fault

Expected behavior See it not seg fault

Information (please complete the following):

mdavidsaver commented 1 year ago

I am not able to replicate with pvxslibs==1.2.2a1 and epicscorelibs==7.0.7.99.0.2a1 from pypi.org.

Can you provide a stack trace of a crash?

coretl commented 1 year ago
$ gdb python 
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python...
(No debugging symbols found in python)
(gdb) run -X dev pvxsioc.py -d test.db
Starting program: /venv/bin/python -X dev pvxsioc.py -d test.db
warning: Error disabling address space randomization: Function not implemented
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Detaching after vfork from child process 346573]
[New Thread 0x7f91711d0640 (LWP 346574)]
[Thread 0x7f91711d0640 (LWP 346574) exited]
IOC Starting w/ [('test.db', '')] 
IOC dbd loaded
[New Thread 0x7f91711d0640 (LWP 346575)]
[New Thread 0x7f91702ef640 (LWP 346576)]
[New Thread 0x7f91700ee640 (LWP 346577)]
2023-06-27T08:31:54.407235120 WARN pvxs.tcp.setup Server unable to bind port 5075, falling back to [::]:39237
IOC rRDD
IOC db loaded
INFO: PVXS QSRV2 is loaded and disabled.
      To enable set: epicsEnvSet("PVXS_QSRV_ENABLE","YES")
      and ensure that $EPICS_IOC_IGNORE_SERVERS does not contain "qsrv2".
Starting iocInit
############################################################################
## EPICS 7.0.7.0
## Rev. 7.0.7.99.0.1
## Rev. Date 7.0.7.99.0.1
############################################################################
[New Thread 0x7f916bfff640 (LWP 346578)]
[New Thread 0x7f916bf7e640 (LWP 346579)]
[New Thread 0x7f916be7d640 (LWP 346580)]
[New Thread 0x7f916bc7c640 (LWP 346581)]
[New Thread 0x7f916ba7b640 (LWP 346582)]
[New Thread 0x7f916b87a640 (LWP 346583)]
[New Thread 0x7f916b679640 (LWP 346584)]
[New Thread 0x7f916b478640 (LWP 346585)]
[New Thread 0x7f916b277640 (LWP 346586)]
[New Thread 0x7f916b076640 (LWP 346587)]
[New Thread 0x7f916ae75640 (LWP 346588)]
[New Thread 0x7f916ac74640 (LWP 346589)]
[New Thread 0x7f916aa73640 (LWP 346590)]
[New Thread 0x7f916a872640 (LWP 346591)]
cas WARNING: Configured TCP port was unavailable.
cas WARNING: Using dynamically assigned TCP port 33655,
cas WARNING: but now two or more servers share the same UDP port.
cas WARNING: Depending on your IP kernel this server may not be
cas WARNING: reachable with UDP unicast (a host's IP in EPICS_CA_ADDR_LIST)
[New Thread 0x7f916a671640 (LWP 346605)]
[New Thread 0x7f916a570640 (LWP 346606)]
[New Thread 0x7f916a46f640 (LWP 346607)]
iocRun: All initialization complete
IOC Running
Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> exit()

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
0x00007f917144f884 in epicsMutex::lock() () from /venv/lib/python3.10/site-packages/epicscorelibs/lib/libCom.so.7.0.7.99.0
(gdb) bt
#0  0x00007f917144f884 in epicsMutex::lock() ()
   from /venv/lib/python3.10/site-packages/epicscorelibs/lib/libCom.so.7.0.7.99.0
#1  0x00007f91704dbea7 in pvxs::ioc::IOCGroupConfigCleanup() ()
   from /venv/lib/python3.10/site-packages/pvxslibs/lib/libpvxsIoc.so.1.2
#2  0x00007f91704e21d0 in pvxs::ioc::pvxsInitHook(initHookState) ()
   from /venv/lib/python3.10/site-packages/pvxslibs/lib/libpvxsIoc.so.1.2
#3  0x00007f917143cc2d in initHookAnnounce ()
   from /venv/lib/python3.10/site-packages/epicscorelibs/lib/libCom.so.7.0.7.99.0
#4  0x00007f9170999345 in iocShutdown () from /venv/lib/python3.10/site-packages/epicscorelibs/lib/libdbCore.so.7.0.7.99.0
#5  0x00007f917142fce5 in epicsExitCallAtExitsPvt ()
   from /venv/lib/python3.10/site-packages/epicscorelibs/lib/libCom.so.7.0.7.99.0
#6  0x00007f917142fddd in epicsExitCallAtExits ()
   from /venv/lib/python3.10/site-packages/epicscorelibs/lib/libCom.so.7.0.7.99.0
#7  0x00007f9171e96e2e in ?? () from /lib/x86_64-linux-gnu/libffi.so.8
#8  0x00007f9171e93493 in ?? () from /lib/x86_64-linux-gnu/libffi.so.8
#9  0x00007f9171ea6451 in ?? () from /usr/lib/python3.10/lib-dynload/_ctypes.cpython-310-x86_64-linux-gnu.so
#10 0x00007f9171ea5a68 in ?? () from /usr/lib/python3.10/lib-dynload/_ctypes.cpython-310-x86_64-linux-gnu.so
#11 0x00005618f2b1c4ab in _PyObject_MakeTpCall ()
#12 0x00005618f2b14815 in _PyEval_EvalFrameDefault ()
#13 0x00005618f2b261ec in _PyFunction_Vectorcall ()
#14 0x00005618f2c2f658 in ?? ()
--Type <RET> for more, q to quit, c to continue without paging--c
#15 0x00005618f2c2e3de in Py_FinalizeEx ()
#16 0x00005618f2c4333c in Py_Exit ()
#17 0x00005618f2c30aff in ?? ()
#18 0x00005618f2c30a2d in PyErr_PrintEx ()
#19 0x00005618f2c2d366 in _PyRun_SimpleFileObject ()
#20 0x00005618f2c2d033 in _PyRun_AnyFileObject ()
#21 0x00005618f2c1e2de in Py_RunMain ()
#22 0x00005618f2bf432d in Py_BytesMain ()
#23 0x00007f91722ced90 in __libc_start_call_main (main=main@entry=0x5618f2bf42f0, argc=argc@entry=6, argv=argv@entry=0x7ffcb6f21848) at ../sysdeps/nptl/libc_start_call_main.h:58
#24 0x00007f91722cee40 in __libc_start_main_impl (main=0x5618f2bf42f0, argc=6, argv=0x7ffcb6f21848, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffcb6f21838) at ../csu/libc-start.c:392
#25 0x00005618f2bf4225 in _start ()
coretl commented 1 year ago

I also get this from a clean venv using your requirements above:

[E7](pvxslibs)[pythonSoftIOC]$ python3 -m venv /venv2
[E7](pvxslibs)[pythonSoftIOC]$ source /venv/bin/activate
(venv) [E7](pvxslibs)[pythonSoftIOC]$ pip install pvxslibs==1.2.2a1 epicscorelibs==7.0.7.99.0.2a1
Requirement already satisfied: pvxslibs==1.2.2a1 in /venv/lib/python3.10/site-packages (1.2.2a1)
Requirement already satisfied: epicscorelibs==7.0.7.99.0.2a1 in /venv/lib/python3.10/site-packages (7.0.7.99.0.2a1)
Requirement already satisfied: setuptools-dso>=2.7a1 in /venv/lib/python3.10/site-packages (from pvxslibs==1.2.2a1) (2.9)
Requirement already satisfied: setuptools in /venv/lib/python3.10/site-packages (from epicscorelibs==7.0.7.99.0.2a1) (67.8.0)
Requirement already satisfied: numpy in /venv/lib/python3.10/site-packages (from epicscorelibs==7.0.7.99.0.2a1) (1.24.3)

[notice] A new release of pip is available: 23.1.1 -> 23.1.2
[notice] To update, run: pip install --upgrade pip
(venv) [E7](pvxslibs)[pythonSoftIOC]$ cat test.db 
record(lsi, "STRING:PLEASE")
{
    field(SIZV, 6500)
    field(INP, {const:"A very long label, longer than 40 characters, that needs a waveform"})
}(venv) [E7](pvxslibs)[pythonSoftIOC]$ python -X dev pvxsioc.py -d test.db 
IOC Starting w/ [('test.db', '')] 
IOC dbd loaded
2023-06-27T08:38:32.172001915 WARN pvxs.tcp.setup Server unable to bind port 5075, falling back to [::]:38411
IOC rRDD
IOC db loaded
INFO: PVXS QSRV2 is loaded and disabled.
      To enable set: epicsEnvSet("PVXS_QSRV_ENABLE","YES")
      and ensure that $EPICS_IOC_IGNORE_SERVERS does not contain "qsrv2".
Starting iocInit
############################################################################
## EPICS 7.0.7.0
## Rev. 7.0.7.99.0.2a1
## Rev. Date 7.0.7.99.0.2a1
############################################################################
cas WARNING: Configured TCP port was unavailable.
cas WARNING: Using dynamically assigned TCP port 44861,
cas WARNING: but now two or more servers share the same UDP port.
cas WARNING: Depending on your IP kernel this server may not be
cas WARNING: reachable with UDP unicast (a host's IP in EPICS_CA_ADDR_LIST)
iocRun: All initialization complete
IOC Running
Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> 
now exiting InteractiveConsole...
Fatal Python error: Segmentation fault

Current thread 0x00007f25a24aa000 (most recent call first):
  File "/venv/lib/python3.10/site-packages/epicscorelibs/ioc.py", line 32 in baseCleanup
Segmentation fault (core dumped)
(venv) [E7](pvxslibs)[pythonSoftIOC]$ python --version
Python 3.10.6
mdavidsaver commented 1 year ago

That stack trace makes the situation clear. I am also able to trigger a crash with softIocPVX. I'm not sure why the python example exits cleanly for me though.

Should be fixed by e51954529a7572a5bb6ac698afc30088d439e2aa

I am confident enough in this fix that I will go ahead with 1.2.2 (and P4P 4.1.8).

coretl commented 12 months ago

Thanks, this fixes it for me