From 0d7dbaf9b9648b4aea8033f71a8516d2abeb18af Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Thu, 5 Aug 2021 16:23:24 +0900 Subject: [PATCH] TLSServer: Fix crash on logging errors In #3330 we added host name information to the error messages but it doesn't care the case when it fails getpeername(2). Signed-off-by: Takuro Ashie --- lib/fluent/plugin_helper/server.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin_helper/server.rb b/lib/fluent/plugin_helper/server.rb index ba0c3dc645..a7609b73df 100644 --- a/lib/fluent/plugin_helper/server.rb +++ b/lib/fluent/plugin_helper/server.rb @@ -709,13 +709,15 @@ def try_tls_accept return true end rescue Errno::EPIPE, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e + peeraddr = (@_handler_socket.peeraddr rescue PEERADDR_FAILED) @log.trace "unexpected error before accepting TLS connection", - host: @_handler_socket.peeraddr[3], port: @_handler_socket.peeraddr[1], error: e + addr: peeraddr[3], host: peeraddr[2], port: peeraddr[1], error: e close rescue nil rescue OpenSSL::SSL::SSLError => e + peeraddr = (@_handler_socket.peeraddr rescue PEERADDR_FAILED) # Use same log level as on_readable @log.warn "unexpected error before accepting TLS connection by OpenSSL", - host: @_handler_socket.peeraddr[3], port: @_handler_socket.peeraddr[1], error: e + host: peeraddr[3], host: peeraddr[2], port: peeraddr[1], error: e close rescue nil end