From 7e32283df3a55f5654f1578c7683e9a7ae92940a Mon Sep 17 00:00:00 2001 From: yhirose Date: Sat, 21 Nov 2026 11:47:48 -0500 Subject: [PATCH] Free OpenSSL's record buffers of a parked TLS connection An idle parked TLS connection took about 24 KB, most of it OpenSSL's read and write buffers. SSL_free_buffers() before parking brings it to about 15 KB; OpenSSL keeps them when a record is pending and makes new ones on the next read. The request rate is unchanged. BoringSSL, LibreSSL, Mbed TLS and wolfSSL are left as they are. --- httplib.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/httplib.h b/httplib.h index 37aed8f8..2bac990c 100644 --- a/httplib.h +++ b/httplib.h @@ -20177,6 +20177,15 @@ struct SSLServer::TlsConnection final : Server::KeepAliveConnection { return serve_on(strm, [this](Request &req) { req.ssl = session; }); } + void release_buffers() override { +#if defined(CPPHTTPLIB_OPENSSL_SUPPORT) && !defined(OPENSSL_IS_BORINGSSL) && \ + !defined(LIBRESSL_VERSION_NUMBER) + // The record buffers are most of an idle session's memory. It keeps them + // when a record is still pending, and makes new ones on the next read. + SSL_free_buffers(static_cast(session)); +#endif + } + void shut_down(bool graceful) override { tls::shutdown(session, graceful); } SSLServer &ssl_svr;