From 814a3a3482fb49f620f24f02b88be55136f8733b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 21 Jun 2021 13:36:05 +0200 Subject: mod_c2s: Guard against LuaSec not returning TLS info (thanks Martin) The :info() method has been observed to return nothing ... sometimes. Unclear what causes it. Perhaps the TLS connection was shut down or hasn't fully settled? The LuaSec code has code paths that return nothing or nil, error, so it is best to guard against it. --- plugins/mod_c2s.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'plugins/mod_c2s.lua') diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index 35ec201a..722932f6 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -117,8 +117,8 @@ function stream_callbacks._streamopened(session, attr) session.encrypted = true; local sock = session.conn:socket(); - if sock.info then - local info = sock:info(); + local info = sock.info and sock:info(); + if type(info) == "table" then (session.log or log)("info", "Stream encrypted (%s with %s)", info.protocol, info.cipher); session.compressed = info.compression; m_tls_params:with_labels(info.protocol, info.cipher):add(1) @@ -294,8 +294,8 @@ function listener.onconnect(conn) -- Check if TLS compression is used local sock = conn:socket(); - if sock.info then - local info = sock:info(); + local info = sock.info and sock:info(); + if type(info) == "table" then (session.log or log)("info", "Stream encrypted (%s with %s)", info.protocol, info.cipher); session.compressed = info.compression; m_tls_params:with_labels(info.protocol, info.cipher):add(1) -- cgit v1.2.3