Skip to content

Defer redis connection until first use (avoid sockets stuck in CLOSE_WAIT) #3618

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jes
Copy link
Contributor

@jes jes commented Apr 3, 2025

Summary
We were seeing OpenSIPS leaving redis client sockets in the CLOSE_WAIT state when redis restarts. This PR prevents this problem.

Details
When redis restarts, the client sockets go into the CLOSE_WAIT state until OpenSIPS next tries to use the socket and then notices that it needs to reconnect.
Some of the OpenSIPS processes open redis sockets that they never use, because the connection is opened immediately even if it doesn't get used.
This is not a major issue, but it means we keep getting alerts for sockets stuck in CLOSE_WAIT.

Solution
This PR fixes the problem by deferring the connection to redis until it is actually used. That way the only sockets that go into CLOSE_WAIT are ones that have been actively used at least once, so we can expect them to get used again, which will clean up the CLOSE_WAIT sockets.

Compatibility
I don't imagine this breaks any scenarios.

Closing issues
N/A

Copy link
Member

@liviuchircu liviuchircu left a comment

Choose a reason for hiding this comment

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

Hey @jes! I would be onboard with this with no hesitation, were it not impacting the startup phase. As of now, say you start OpenSIPS with Redis offline -- it gives an Error and fails startup. If we merge this, there is an added side-effect of OpenSIPS now successfully starting with an offline Redis.

Is this subtle startup behavior change something we want? Is it for the better? And, also worth asking, are the current, "indefinitely" temporary CLOSE_WAIT sockets that harmful?

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

Successfully merging this pull request may close these issues.

2 participants