Skip to content

Commit

Permalink
fix(tcp-log):repeated sslhandshake in [tcp-log] plugin (#11803)
Browse files Browse the repository at this point in the history
* FIX:Repeated sslhandshake in [tcp-log] plugin

* add changelog

* update message as the comments

* Update changelog/unreleased/kong/fix-tcp-log-sslhandshake.yml

Co-authored-by: tzssangglass <tzssangglass@apache.org>

---------

Co-authored-by: tzssangglass <tzssangglass@apache.org>
(cherry picked from commit 3fed60b)
  • Loading branch information
chenyyyang authored and github-actions[bot] committed Oct 26, 2023
1 parent 7b7c42b commit 44a381a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/fix-tcp-log-sslhandshake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**tcp-log**: fix an issue that repeated ssl handshake"
type: bugfix
scope: Plugin
11 changes: 9 additions & 2 deletions kong/plugins/tcp-log/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ local function log(premature, conf, message)
return
end

if conf.tls then
ok, err = sock:sslhandshake(true, conf.tls_sni, false)
local times, err = sock:getreusedtimes()
if not times then
kong.log.err("failed to get socket reused time to ", host, ":", tostring(port), ": ", err)
sock:close()
return
end

if conf.tls and times == 0 then
ok, err = sock:sslhandshake(false, conf.tls_sni, false)
if not ok then
kong.log.err("failed to perform TLS handshake to ", host, ":", port, ": ", err)
sock:close()
Expand Down

0 comments on commit 44a381a

Please sign in to comment.