bugfix: sslhandshake lost verify error when handshake completed immediately#2506
Merged
zhuizhuhaomeng merged 1 commit intoJun 5, 2026
Conversation
…iately After ngx_ssl_handshake(c) returns NGX_OK, the handshake handler may still record a verify error in u->error_ret via SSL_get_verify_result(). The old code only checked rc == NGX_ERROR and missed u->error_ret, returning FFI_OK with an unread error. Added u->error_ret != NULL check so the Lua caller receives the SSL error instead of a misleading "closed" on the next socket operation.
zhuizhuhaomeng
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
sister PR: openresty/lua-resty-core#533
Summary
When
ngx_ssl_handshake(c)completes synchronously (NGX_OK), the C handler may still record a verify error inu->error_ret. The old code only checkedrc == NGX_ERROR, so the error was silently lost. The primary fix is on the C side: also checku->error_ret. The Lua side then no longer needs its special early-return path, which is removed.The bug
The C FFI returned
FFI_OKeven thoughu->error_retwas set. In Lua, theFFI_OKpath returnedtrueearly without entering the error-handling loop, so callers sawsslhandshake() -> truefollowed by a misleadingsock:send() -> "closed".The fix
C side (
lua-nginx-module): the primary fix. One line — also checku->error_ret:Now the C FFI returns
FFI_ERRORwhenever a verify error was recorded, including the synchronous-handshake case.Lua side (
lua-resty-core): simplification that follows from the C fix. SinceFFI_ERRORis now surfaced on the first call (not just on async resume), the specialFFI_OKearly-return path is removed:And
get_sslhandshake_result()is added in theFFI_ERRORbranch soerrmsg/openssl_error_codeare populated even when the error comes from the first call (not a yield/resume).I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.