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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook up the keepAlive after a successful connect #1554

Merged
merged 2 commits into from Mar 31, 2022
Merged

Hook up the keepAlive after a successful connect #1554

merged 2 commits into from Mar 31, 2022

Conversation

marcbachmann
Copy link
Collaborator

I haven't tested it yet as I'm running on macos and there's no way to read out the socket options, but this should fix #1339

Changelog

  • 馃悰 Call socket.setKeepAlive(true, ms) after a successful connect as workaround for a node issue where it won't work when it's called before a successful connect

@marcbachmann
Copy link
Collaborator Author

marcbachmann commented Mar 30, 2022

Alternatively we could use socket.connect({keepAlive: true, noDelay: true}[, listener]): https://nodejs.org/api/net.html#socketconnectoptions-connectlistener
That might be cleaner, but at the moment net.createConnection is in use at several places.

@luin
Copy link
Collaborator

luin commented Mar 30, 2022

Is there a link explains why it didn't work?

@marcbachmann
Copy link
Collaborator Author

nodejs/node#31663

@marcbachmann

This comment was marked as resolved.

@marcbachmann
Copy link
Collaborator Author

Passing connection options during createConnection is more straight forward. I've pushed the changes.

@marcbachmann marcbachmann force-pushed the fix-keepalive branch 2 times, most recently from 35e2a99 to f39acf4 Compare March 30, 2022 20:24
@luin
Copy link
Collaborator

luin commented Mar 31, 2022

Is this ready for review? I think we also need to change SentinelConnector?

@marcbachmann
Copy link
Collaborator Author

marcbachmann commented Mar 31, 2022

image

The noDelay and keepAlive properties on the connect options only got added in node 17.7.0. So I'll need to revert that change back to a manual call after connect 馃槩

@marcbachmann
Copy link
Collaborator Author

This is now ready. I've decided to move it back into the redis constructor to keep it in one place with the reconnect handling.
So it should work now for sentinel and regular use. I also found one small issue with sentinel where the failover event listener wasn't set up properly. That's in the second commit now.

@luin luin merged commit ac00a00 into main Mar 31, 2022
@luin luin deleted the fix-keepalive branch March 31, 2022 13:50
@luin
Copy link
Collaborator

luin commented Mar 31, 2022

LGTM! Awesome 馃憤

@github-actions
Copy link

馃帀 This PR is included in version 5.0.3 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

when keepAlive parameter is set, the TCP keep-alive is enabled but the specified timeout is not applied
2 participants