PyS2OPC server: in rare case an assertion is be raised when server is stopping
Description
In rare case an assertion is raised when server is stopping in test validation::pys2opc_server-0-read-write.py
:
python3: /builds/systerel/S2OPC/src/Common/helpers/sopc_singly_linked_list.c:394: SOPC_SLinkedList_RemoveFromId: Assertion `list != NULL' failed.
Analysis
After analysis it seems the issue is that the function SOPC_EventTimer_Cancel
is concurrently called with SOPC_EventTimer_Clear
leading to use a NULL pointer whereas it is not expected.
Note: PyS2OPC server uses low-level server API (all others samples/tests now use the frontend) and does not seem to wait for endpoints to be closed prior to clear the toolkit which might explain why this issue was only raised in this test.
Implementation
In order to avoid this issue several modifications should be done:
- Avoid to call
SOPC_EventTimer_Clear
when theSOPC_EventTimer_*
functions might be called by other toolkit threads - Since the timer module might trigger events to other threads, it might be interesting to have a
SOPC_EventTimer_PreClear
which prevent it prior to stop other threads and then callSOPC_EventTimer_Clear
to free memory. - The different layers services/secure channels/socket should manage attempts to enqueue events after clear due to their inter-dependencies
- The
SOPC_SLinkedList*
functions should not use assertions for parameters and should return "NULL" values when failing
Edited by Vincent Monfort