Fix #3226: WolfSSL/OpenSSL connections close after handshake with built-in TCP #3301
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes issue #3226 where connections close immediately after TLS handshake when using WolfSSL or OpenSSL with Mongoose's built-in TCP/IP stack (MIP).
Problem
Root Cause
SSL may read and buffer multiple TLS records internally during handshake or read operations. Mongoose was not checking
SSL_pending()
to detect this buffered data, causing the event loop to think the connection was idle and close it prematurely.Solution
Added
mg_tls_pending()
checks at two critical points:mg_tls_handshake
): Check if SSL buffered application data during handshake and setc->is_readable
to signal the event loopmg_tls_recv
): Check if more data remains buffered afterSSL_read()
and keepc->is_readable
set to continue processingThis ensures the event loop continues processing buffered SSL data even when the underlying socket has no new data available.
Impact
src/tls_openssl.c
)Testing
mg_tls_pending()
helper functionFiles Changed
src/tls_openssl.c
: Added SSL_pending() checks (+10 lines)