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

Support for ping check to get healthy connections #9

Merged
merged 1 commit into from
Aug 8, 2019
Merged

Support for ping check to get healthy connections #9

merged 1 commit into from
Aug 8, 2019

Conversation

kawamanza
Copy link
Contributor

Closes #8

@codecov-io
Copy link

codecov-io commented Aug 7, 2019

Codecov Report

Merging #9 into master will decrease coverage by 5.18%.
The diff coverage is 43.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #9      +/-   ##
==========================================
- Coverage   84.02%   78.83%   -5.19%     
==========================================
  Files           3        3              
  Lines         169      189      +20     
==========================================
+ Hits          142      149       +7     
- Misses         27       40      +13
Impacted Files Coverage Δ
pymysqlpool/pool.py 62.26% <43.33%> (-6.35%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cbca30a...2832409. Read the comment docs.

c.ping()
except:
self.current_size -= 1
if retry_count < 10: c = self.__get_conn(retry_count+1)
Copy link
Owner

@prprprus prprprus Aug 8, 2019

Choose a reason for hiding this comment

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

Assume retry exceeds 10, ping() still fails. Is there need to remove this invalid conn and recreate a conn, or throw an exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the ping() fails, the conn is discarded and another conn is fetched from the pool. The retry_count is used to to get and return the first healthy conn from the pool a couple of times. If the conn object fails on trying reconnect, maybe the object has some problem with its internal properties. But... if other instances have the same problem, maybe there is a network problem on going, and no conn will be returned anymore. This implementation just return a None conn on a network problem occurring, but we can make a custom exception if you prefer.

Copy link
Owner

@prprprus prprprus Aug 8, 2019

Choose a reason for hiding this comment

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

Oh, ping() will reconnect, I forgot it 😅...

Nice pr 👍🎉👏, merged.

@prprprus prprprus merged commit d40775b into prprprus:master Aug 8, 2019
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.

MySQL Server has gone away
3 participants