diff --git a/lib/httpx/connection/http2.rb b/lib/httpx/connection/http2.rb index d63aca53..4ca0d501 100644 --- a/lib/httpx/connection/http2.rb +++ b/lib/httpx/connection/http2.rb @@ -73,8 +73,11 @@ module HTTPX end def close - @connection.goaway unless @connection.state == :closed emit(:close) + unless @connection.state == :closed + @connection.goaway + emit(:timeout, @options.timeout[:close_handshake_timeout]) + end end def empty? diff --git a/lib/httpx/options.rb b/lib/httpx/options.rb index 3a9f6e18..1d11ce1a 100644 --- a/lib/httpx/options.rb +++ b/lib/httpx/options.rb @@ -11,6 +11,7 @@ module HTTPX MAX_BODY_THRESHOLD_SIZE = (1 << 10) * 112 # 112K KEEP_ALIVE_TIMEOUT = 20 SETTINGS_TIMEOUT = 10 + CLOSE_HANDSHAKE_TIMEOUT = 10 CONNECT_TIMEOUT = READ_TIMEOUT = WRITE_TIMEOUT = 60 REQUEST_TIMEOUT = OPERATION_TIMEOUT = nil @@ -39,6 +40,7 @@ module HTTPX :timeout => { connect_timeout: CONNECT_TIMEOUT, settings_timeout: SETTINGS_TIMEOUT, + close_handshake_timeout: CLOSE_HANDSHAKE_TIMEOUT, operation_timeout: OPERATION_TIMEOUT, keep_alive_timeout: KEEP_ALIVE_TIMEOUT, read_timeout: READ_TIMEOUT, diff --git a/sig/options.rbs b/sig/options.rbs index 43abe883..484b564c 100644 --- a/sig/options.rbs +++ b/sig/options.rbs @@ -9,9 +9,10 @@ module HTTPX OPERATION_TIMEOUT: Integer KEEP_ALIVE_TIMEOUT: Integer SETTINGS_TIMEOUT: Integer + CLOSE_HANDSHAKE_TIMEOUT: Integer DEFAULT_OPTIONS: Hash[Symbol, untyped] - type timeout_type = :connect_timeout | :settings_timeout | :operation_timeout | :keep_alive_timeout | :read_timeout | :write_timeout | :request_timeout + type timeout_type = :connect_timeout | :settings_timeout | :close_handshake_timeout | :operation_timeout | :keep_alive_timeout | :read_timeout | :write_timeout | :request_timeout type timeout = Hash[timeout_type, Numeric?] def self.new: (?options) -> instance diff --git a/test/options_test.rb b/test/options_test.rb index 65434507..caaa0bd6 100644 --- a/test/options_test.rb +++ b/test/options_test.rb @@ -80,6 +80,7 @@ class OptionsTest < Minitest::Test :timeout => { connect_timeout: 60, settings_timeout: 10, + close_handshake_timeout: 10, operation_timeout: nil, keep_alive_timeout: 20, read_timeout: 60,