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.
This commit is contained in:
yhirose committed 2026-11-21 11:47:48 -05:00
1 parent 76e1a9c4c9
commit 7e32283df3
1 file changed
+9
+9
View File
@@ -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<SSL *>(session));
#endif
}
void shut_down(bool graceful) override { tls::shutdown(session, graceful); }
SSLServer &ssl_svr;