Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If heartbeats are disabled, do not use a read timeout when reading frame header #551

Merged
merged 2 commits into from
Apr 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions lib/bunny/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1177,22 +1177,11 @@ def open_connection
@logger.debug { "Heartbeat interval negotiation: client = #{@client_heartbeat}, server = #{connection_tune.heartbeat}, result = #{@heartbeat}" }
@logger.info "Heartbeat interval used (in seconds): #{@heartbeat}"

# We set the read_write_timeout to twice the heartbeat value
# We set the read_write_timeout to twice the heartbeat value,
# and then some padding for edge cases.
# This allows us to miss a single heartbeat before we time out the socket.
#
# Since RabbitMQ can be configured to disable heartbeats (bad idea but technically
# possible nonetheless), we need to take both client and server values into
# consideration when deciding about using the heartbeat value for read timeouts.
@transport.read_timeout = if heartbeat_disabled?(@client_heartbeat) || heartbeat_disabled?(@heartbeat)
@logger.debug { "Will use default socket read timeout of #{Transport::DEFAULT_READ_TIMEOUT}" }
Transport::DEFAULT_READ_TIMEOUT
else
# pad to account for edge cases. MK.
n = @heartbeat * 2.2
@logger.debug { "Will use socket read timeout of #{n}" }
n
end

@transport.read_timeout = @heartbeat * 2.2
@logger.debug { "Will use socket read timeout of #{@transport.read_timeout}" }

# if there are existing channels we've just recovered from
# a network failure and need to fix the allocated set. See issue 205. MK.
Expand Down
4 changes: 4 additions & 0 deletions lib/bunny/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class Transport
attr_reader :tls_context, :verify_peer, :tls_ca_certificates, :tls_certificate_path, :tls_key_path

attr_writer :read_timeout
def read_timeout=(v)
@read_timeout = v
@read_timeout = nil if @read_timeout == 0
end

def initialize(session, host, port, opts)
@session = session
Expand Down