From 5e50d2677d45c680bf28f15724625fd0afb88bc2 Mon Sep 17 00:00:00 2001 From: lijunlong Date: Tue, 6 Aug 2024 12:45:49 +0800 Subject: [PATCH] bugfix: fixed keepalive error in cosocket. Go to https://github.com/openresty/lua-nginx-module/pull/2347 for more details. --- src/ngx_stream_lua_socket_tcp.c | 10 ++++++++++ t/129-ssl-socket.t | 10 +++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ngx_stream_lua_socket_tcp.c b/src/ngx_stream_lua_socket_tcp.c index 9d5472a2..b37c10ba 100644 --- a/src/ngx_stream_lua_socket_tcp.c +++ b/src/ngx_stream_lua_socket_tcp.c @@ -5618,6 +5618,16 @@ ngx_stream_lua_socket_keepalive_close_handler(ngx_event_t *ev) "check stale events"); n = recv(c->fd, buf, 1, MSG_PEEK); +#if (NGX_STREAM_SSL) + /* ignore ssl protocol data like change cipher spec */ + if (n == 1 && c->ssl != NULL) { + n = c->recv(c, (unsigned char *) buf, 1); + if (n == NGX_AGAIN) { + n = -1; + ngx_socket_errno = NGX_EAGAIN; + } + } +#endif /* NGX_STREAM_SSL */ if (n == -1 && ngx_socket_errno == NGX_EAGAIN) { /* stale event */ diff --git a/t/129-ssl-socket.t b/t/129-ssl-socket.t index 1a158b17..c3fc2f15 100644 --- a/t/129-ssl-socket.t +++ b/t/129-ssl-socket.t @@ -1533,11 +1533,11 @@ set keepalive: 1 nil --- grep_error_log eval: qr/stream lua ssl (?:set|save|free) session: [0-9A-F]+/ --- grep_error_log_out eval qr/^stream lua ssl save session: ([0-9A-F]+) -stream lua ssl save session: \1 -stream lua ssl save session: \1 -stream lua ssl free session: \1 -stream lua ssl free session: \1 -stream lua ssl free session: \1 +stream lua ssl save session: ([0-9A-F]+) +stream lua ssl save session: ([0-9A-F]+) +stream lua ssl free session: ([0-9A-F]+) +stream lua ssl free session: ([0-9A-F]+) +stream lua ssl free session: ([0-9A-F]+) $/ --- error_log