[go: up one dir, main page]

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

4d7db8ae

Steps to reproduce

  1. Create a connection with SOPC_ClientHelper_Connect for a given configuration cfg
  2. Send an important amount of requests to a server (e.g. 10 000) and keep trace of the context sent
  3. Quickly stops the server before end of requests treatment
  4. Wait for disconnection callback to be called
  5. 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:

  1. SC receive disconnection and send it to service layer
  2. Service layer enqueued some new messages to send
  3. SC layer sends back the messages
  4. Service layer acknowledge disconnection and destroy context
  5. 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.

Edited by Vincent Monfort