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

Disable heartbeats if hearbeat set to 0 #469

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function openFrames(vhost, query, credentials, extraClientProperties) {
// tune-ok
'channelMax': intOrDefault(query.channelMax, 0),
'frameMax': intOrDefault(query.frameMax, 0x1000),
'heartbeat': intOrDefault(query.heartbeat, 0),
'heartbeat': intOrDefault(query.heartbeat, null),

// open
'virtualHost': vhost,
Expand Down
4 changes: 2 additions & 2 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ C.open = function(allFields, openCallback0) {
// frameMax, but we'll leave that to the server to enforce). In
// all cases, `0` really means "no limit", or rather the highest
// value in the encoding, e.g., unsigned short for channelMax.
if (server === 0 || desired === 0) {
if (server === 0 || desired === 0 || desired === null) {
// i.e., whichever places a limit, if either
return Math.max(server, desired);
}
Expand Down Expand Up @@ -227,7 +227,7 @@ C.open = function(allFields, openCallback0) {
tunedOptions.channelMax =
negotiate(fields.channelMax, allFields.channelMax);
tunedOptions.heartbeat =
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this PR is old and @squaremo has reviewed / suggested a change, but I am thinking this is a simpler, clearer solution.

Suggested change
tunedOptions.heartbeat =
if (allFields.heartbeat !== 0) {
tunedOptions.heartbeat =
negotiate(fields.heartbeat, allFields.heartbeat);
}

This would also facilitate revert of the change @ line 192 above.

negotiate(fields.heartbeat, allFields.heartbeat);
allFields.heartbeat === null ? fields.heartbeat : allFields.heartbeat
send(defs.ConnectionTuneOk);
send(defs.ConnectionOpen);
expect(defs.ConnectionOpenOk, onOpenOk);
Expand Down