Defer redis connection until first use (avoid sockets stuck in CLOSE_WAIT) #3618
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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