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

Do not leak psycopg2 connections during testing which can lead to fla… #628

Merged
merged 1 commit into from
Mar 17, 2021

Conversation

gkokolatos
Copy link
Collaborator

…kyness

According to psycopg2 documentation connections are not closed on context exit.
This is in contrast with connection cursors that actually do so.

It is not an inherent problem in itself, however, calls to get_state() in a
loop, such as from wait_until_*, can overflow the connection limits and cause
the test suite to fail. This is particularly noticable when the system is slow
to respond, for example if it is run under valgrind.

This might address other objerved flakyness in the tests due to connection
exhaustion with messages as:
"psycopg2.OperationalError: FATAL: sorry, too many clients already"

Run into this repeatedly while profiling in order to address #582
Might be related with the comment in #512#issuecomment-767205595

…kyness

According to psycopg2 documentation connections are not closed on context exit.
This is in contrast with connection cursors that actually do so.

It is not an inherent problem in itself, however, calls to get_state() in a
loop, such as from wait_until_*, can overflow the connection limits and cause
the test suite to fail. This is particularly noticable when the system is slow
to respond, for example if it is run under valgrind.

This might address other objerved flakyness in the tests due to connection
exhaustion with messages as:
"psycopg2.OperationalError: FATAL:  sorry, too many clients already"
result = None
conn = psycopg2.connect(self.connection_string())

with conn:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we still need to have a context handler on the connection object if the context handler doesn't close the connection anyway? What it is used for then?

@gkokolatos
Copy link
Collaborator Author

gkokolatos commented Mar 17, 2021 via email

@DimCitus DimCitus merged commit 2437111 into hapostgres:master Mar 17, 2021
@DimCitus
Copy link
Collaborator

Ah yeah that's per psycopg2 docs. Perfect then, many thanks again for your contributions!

@DimCitus DimCitus assigned DimCitus and gkokolatos and unassigned DimCitus Mar 17, 2021
@DimCitus DimCitus added the bug Something isn't working label Mar 17, 2021
@DimCitus DimCitus added this to the Sprint 2021 W11 W12 milestone Mar 17, 2021
@gkokolatos
Copy link
Collaborator Author

gkokolatos commented Mar 17, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants