Merge branch 'issue-288' into 'master'

cleanly close the connection on HTTP2 protocol error

Closes #288, #294, and #295

See merge request os85/httpx!325
This commit is contained in:
HoneyryderChuck 2024-02-01 11:18:18 +00:00
commit 566b804b65
2 changed files with 5 additions and 3 deletions

View File

@ -522,14 +522,15 @@ module HTTPX
Errno::ENETUNREACH, Errno::ENETUNREACH,
Errno::EPIPE, Errno::EPIPE,
Errno::ENOENT, Errno::ENOENT,
SocketError => e SocketError,
IOError => e
# connect errors, exit gracefully # connect errors, exit gracefully
error = ConnectionError.new(e.message) error = ConnectionError.new(e.message)
error.set_backtrace(e.backtrace) error.set_backtrace(e.backtrace)
connecting? && callbacks_for?(:connect_error) ? emit(:connect_error, error) : handle_error(error) connecting? && callbacks_for?(:connect_error) ? emit(:connect_error, error) : handle_error(error)
@state = :closed @state = :closed
emit(:close) emit(:close)
rescue TLSError => e rescue TLSError, HTTP2Next::Error::ProtocolError, HTTP2Next::Error::HandshakeError => e
# connect errors, exit gracefully # connect errors, exit gracefully
handle_error(e) handle_error(e)
connecting? && callbacks_for?(:connect_error) ? emit(:connect_error, e) : handle_error(e) connecting? && callbacks_for?(:connect_error) ? emit(:connect_error, e) : handle_error(e)

View File

@ -78,7 +78,8 @@ module HTTPX
rescue Errno::ECONNREFUSED, rescue Errno::ECONNREFUSED,
Errno::EADDRNOTAVAIL, Errno::EADDRNOTAVAIL,
Errno::EHOSTUNREACH, Errno::EHOSTUNREACH,
SocketError => e SocketError,
IOError => e
raise e if @ip_index <= 0 raise e if @ip_index <= 0
log { "failed connecting to #{@ip} (#{e.message}), trying next..." } log { "failed connecting to #{@ip} (#{e.message}), trying next..." }