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

Switch to pessimistic SQL disconnect handling #1284

Merged

Conversation

Projects
None yet
3 participants
@c-w
Copy link
Contributor

commented May 31, 2018

Previously we were using optimistic disconnect handling for the database connection pool: assume that all the connections are live and recycle them before a certain timeout just in case the server kills the connections after a certain period of inactivity. This approach reduced the frequency of "MySQL went away" errors, but it turns out that it didn't eliminate them.

As such, this change switches to pessimistic disconnect handling: before using a given connection, it is first tested for liveness by SQLAlchemy. This is implemented by passing pool_pre_ping to the create_engine call (docs). Note that this option was only introduced in SQLAlchemy 1.2 (announcement) so this change also updates the SQLAlchemy dependency to the latest release.

c-w added some commits May 31, 2018

Switch to pessimistic SQL disconnect handling
Previously we were using optimistic disconnect handling for the database
connection pool: assume that all the connections are live and recycle
them before a certain timeout just in case the server kills the
connections after a certain period of inactivity. This approach reduced
the frequency of "MySQL went away" errors, but it turns out that it
didn't eliminate them.

As such, this change switches to pessimistic disconnect handling: before
using a given connection, it is first tested for liveness by SQLAlchemy.
This is implemented by passing `pool_pre_ping` to the `create_engine`
call [1]. Note that this option was only introduced in SQLAlchemy 1.2
[2] so this change also updates the SQLAlchemy dependency to the latest
release.

[1] http://docs.sqlalchemy.org/en/latest/core/pooling.html#pool-disconnects-pessimistic
[2] https://twitter.com/sqlalchemy/status/884415051125452802
@Sumukh

Sumukh approved these changes May 31, 2018

@colinschoen
Copy link
Member

left a comment

LGTM

@colinschoen colinschoen merged commit 24bb16b into okpy:master May 31, 2018

2 checks passed

ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@c-w c-w deleted the icokpy:bug/c-w/pessimistic-disconnect-handling branch May 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.