Client API: async response callback not called for request sending failure
Description
In case of request sending failure happening during a disconnection from server side, the asynchronous response callback SOPC_ServiceAsyncResp_Fct was not called and thus the context associated never returned.
Code version and environment identification
Steps to reproduce
- Create a connection with
SOPC_ClientHelper_Connectfor a given configurationcfg - Send an important amount of requests to a server (e.g. 10 000) and keep trace of the context sent
- Quickly stops the server before end of requests treatment
- Wait for disconnection callback to be called
- Check and wait for all context to be received back
Some contexts are never received and memory leak occurs for those contexts.
Analysis
The issue is due to asynchronous behavior between SC and Services layer:
- SC receive disconnection and send it to service layer
- Service layer enqueued some new messages to send
- SC layer sends back the messages
- Service layer acknowledge disconnection and destroy context
- Service layer receive the message back but do not trigger client API because connection context is already destroyed
Security impact
No security impact.
Possible fixes
When Service layer acknowledge disconnection, it shall iterate on all pending requests recorded in request_handle_bs module and trigger client API those request sending failed. And only after that it shall destroy the connection context.
The same shall be done when a session is closed since request contexts returned on a connection closure are excluded for those on a closed session, the better is then to return them when the session is closed to the application.
Moreover the client state machine shall avoid to change state to error as it is not possible to disconnect / properly clean the connection in this case.
Note: messages sent back from SC to Services layer are still ignored but we already notified client API and return the application context.