Skip to content

RDKB-64644: Potential Fix for SE051 ENGINE memory leak in telemetry HTTP pool#360

Merged
shibu-kv merged 1 commit into
developfrom
topic/RDKB-64644
May 4, 2026
Merged

RDKB-64644: Potential Fix for SE051 ENGINE memory leak in telemetry HTTP pool#360
shibu-kv merged 1 commit into
developfrom
topic/RDKB-64644

Conversation

@tabbas651
Copy link
Copy Markdown
Contributor

Reason for change: On HROT platforms using the SE051 secure element (XB10/XER10/SXB10), the e4sss OpenSSL ENGINE accumulates per-session hardware state (APDU session objects, secure channel buffers) across mTLS operations. Unlike SE050 (XB8), the SE051 ENGINE allocates larger per-session state that is not released by curl's connection cache management, OPENSSL_thread_stop, or ERR_clear_error() alone. This causes a progressive memory leak (~5MB baseline increase + ~5MB growth over 10+ days) in the telemetry process.

  1. set CURLOPT_FORBID_REUSE=1 so curl closes the
    TCP+TLS connection after each request. This triggers the natural OpenSSL cleanup path: SSL_CTX_free -> EC_KEY_free -> ENGINE_finish, releasing the hardware session state.
    2)Add ERR_clear_error() in both GET and POST xPKI retry loops to drain the OpenSSL error queue between retries, preventing ENGINE-internal error state accumulation. Test Procedure: please refered from the ticket
    Risks: High
    Signed-off-by: Thamim Razith tabbas651@cable.comcast.com

…TTP pool

Reason for change: On HROT platforms using the SE051 secure element (XB10/XER10/SXB10), the e4sss OpenSSL ENGINE accumulates per-session hardware state (APDU session objects, secure channel buffers) across mTLS operations. Unlike SE050 (XB8), the SE051 ENGINE allocates larger per-session state that is not released by curl's connection cache management, OPENSSL_thread_stop, or ERR_clear_error() alone. This causes a progressive memory leak (~5MB baseline increase + ~5MB growth over 10+ days) in the telemetry process.

1) set CURLOPT_FORBID_REUSE=1 so curl closes the
TCP+TLS connection after each request.  This triggers the natural
OpenSSL cleanup path: SSL_CTX_free -> EC_KEY_free -> ENGINE_finish,
releasing the hardware session state.
2)Add ERR_clear_error() in both GET and POST xPKI retry loops to drain the OpenSSL error queue between retries, preventing ENGINE-internal error state accumulation.
Test Procedure:  please refered from the ticket
Risks: High
Signed-off-by: Thamim  Razith <tabbas651@cable.comcast.com>
@tabbas651 tabbas651 requested a review from a team as a code owner May 4, 2026 16:04
Copilot AI review requested due to automatic review settings May 4, 2026 16:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to mitigate a long-running memory leak observed on HROT platforms using the SE051 OpenSSL ENGINE during repeated mTLS operations in the telemetry HTTP connection pool.

Changes:

  • Forces libcurl to close connections after each request by setting CURLOPT_FORBID_REUSE=1 on pooled easy handles.
  • Clears the OpenSSL per-thread error queue (ERR_clear_error()) inside the GET/POST xPKI retry loops to avoid error-state accumulation between retries.
  • Reorders an ownership note comment near the OpenSSL error-queue cleanup in http_pool_get().

CURL_SETOPT_CHECK(pool_entries[i].easy_handle, CURLOPT_FORBID_REUSE, 0L);
//Disable connection reuse (FORBID_REUSE=1) so that
// curl tears down the TLS session after each request. This causes
// OpenSSL to call SSL_CTX_free → EC_KEY_free → ENGINE_finish through
Comment thread source/protocol/http/multicurlinterface.c
Comment on lines 618 to 630
// Execute the request and retry incase of certificate related error
curl_code = curl_easy_perform(easy);

long http_code;
curl_easy_getinfo(easy, CURLINFO_RESPONSE_CODE, &http_code);

if(curl_code != CURLE_OK || http_code != 200)
{
T2Error("%s: Failed to establish connection using xPKI certificate: %s, Curl failed : %d\n", __func__, pCertFile, curl_code);
// Drain OpenSSL error queue between retries to prevent
// ENGINE-internal error state accumulation (HROT/SE051).
ERR_clear_error();
}
@shibu-kv
Copy link
Copy Markdown
Contributor

shibu-kv commented May 4, 2026

Bypassing L2 failures and merging as the test failures are not from these changes. Test failures appear to be due to test docker infrastructure changes from recent release - https://github.com/rdkcentral/docker-device-mgt-service-test/releases/tag/1.7.13

@shibu-kv shibu-kv merged commit 4788834 into develop May 4, 2026
16 of 18 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators May 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants