Skip to content

fix(client): Avoids infinite promise-chaining when socket's creation fails #2295

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

Merged
merged 4 commits into from
Oct 26, 2022

Conversation

JonasFaure
Copy link
Contributor

Description

This change prevents a memory leak when a Redis client tries to connect to an unavailable host. This is achieve by switching from a recursive to an iterative approach.

When a Redis instance fails, our clients slowly build up memory until they get killed.

#2134

First, I had to slightly change the tests' implementation to work around timeout issues when running the tests, ie : specifying a timeout using the connectTimeout argument & giving up mocking time by specifying a very small retry delay. This commit should preferably be reverted if someone who manages to run tests locally can validate my implementation with the previous implementation for those tests 🤷

Second, I swapped the recursive call to connect for a do{}while loop and leverage the #this.isReady property as the exit condition.


Checklist

  • Does npm test pass with this change (including linting)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

@JonasFaure JonasFaure marked this pull request as ready for review October 17, 2022 08:58
@leibale leibale linked an issue Oct 21, 2022 that may be closed by this pull request
@leibale
Copy link
Contributor

leibale commented Oct 21, 2022

@JonasFaure nice one! sorry for the long delay, I was on vacation... I'll release a version with this fix next week :)

@codecov-commenter
Copy link

codecov-commenter commented Oct 21, 2022

Codecov Report

Base: 95.85% // Head: 95.85% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (7d7cff7) compared to base (e1c0580).
Patch coverage: 84.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2295   +/-   ##
=======================================
  Coverage   95.85%   95.85%           
=======================================
  Files         433      433           
  Lines        4001     4004    +3     
  Branches      451      451           
=======================================
+ Hits         3835     3838    +3     
  Misses        102      102           
  Partials       64       64           
Impacted Files Coverage Δ
packages/client/lib/client/socket.ts 80.35% <84.00%> (+0.35%) ⬆️
index.ts 100.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

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.

Memory leak on repeated connection failures
3 participants