From dd0473e7cf3e059f9b21eb8213683b06f8d96113 Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Thu, 25 Jan 2024 00:05:37 +0000 Subject: [PATCH 1/2] cleanly close the connection on HTTP2 protocol error when the HTTP/2 connection suffers an irrecovable error on the protocol level, it has to be terminated --- lib/httpx/connection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/httpx/connection.rb b/lib/httpx/connection.rb index 7c4fb102..74f1783e 100644 --- a/lib/httpx/connection.rb +++ b/lib/httpx/connection.rb @@ -529,7 +529,7 @@ module HTTPX connecting? && callbacks_for?(:connect_error) ? emit(:connect_error, error) : handle_error(error) @state = :closed emit(:close) - rescue TLSError => e + rescue TLSError, HTTP2Next::Error::ProtocolError, HTTP2Next::Error::HandshakeError => e # connect errors, exit gracefully handle_error(e) connecting? && callbacks_for?(:connect_error) ? emit(:connect_error, e) : handle_error(e) From 5a08853e7ac06def7f18fc317c17ec3911e88e0a Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Thu, 25 Jan 2024 00:15:27 +0000 Subject: [PATCH 2/2] rescue from IOError and terminate the connection contrary to what was probably assumed, IOError is not a SocketError... Closes #295 --- lib/httpx/connection.rb | 3 ++- lib/httpx/io/tcp.rb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/httpx/connection.rb b/lib/httpx/connection.rb index 74f1783e..bc2b0c3e 100644 --- a/lib/httpx/connection.rb +++ b/lib/httpx/connection.rb @@ -522,7 +522,8 @@ module HTTPX Errno::ENETUNREACH, Errno::EPIPE, Errno::ENOENT, - SocketError => e + SocketError, + IOError => e # connect errors, exit gracefully error = ConnectionError.new(e.message) error.set_backtrace(e.backtrace) diff --git a/lib/httpx/io/tcp.rb b/lib/httpx/io/tcp.rb index ea990f6d..a16ad73a 100644 --- a/lib/httpx/io/tcp.rb +++ b/lib/httpx/io/tcp.rb @@ -78,7 +78,8 @@ module HTTPX rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL, Errno::EHOSTUNREACH, - SocketError => e + SocketError, + IOError => e raise e if @ip_index <= 0 log { "failed connecting to #{@ip} (#{e.message}), trying next..." }