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

Remove callbacks from a bad file descriptor immediately #139

Merged
merged 2 commits into from Sep 8, 2016
Merged

Remove callbacks from a bad file descriptor immediately #139

merged 2 commits into from Sep 8, 2016

Conversation

not-even
Copy link
Contributor

@not-even not-even commented Sep 5, 2016

Previously, the callback removal was postponed until .close() call, and
sometimes this .close() call cleared a file descriptor from a callback set
by another connection object (if the file desriptor was closed by psycopg2 when
an error occurred, and then opened again for a new connection).

The effect of this was, when making tens of parallel connections, an error in
one of them made another time out.

Now, if a psycopg2 error occurs, and the file descriptor has gone bad, the
callback is removed immediately, and the aiopg connection object 'forgets'
about this file descriptor (self._fileno = None), and doesn't try to remove
callbacks in .close().

If there were no errors, callbacks are still removed during .close() call.

Fixes #138.

Previously, the callback removal was postponed until .close() call, and
sometimes this .close() call cleared a file descriptor from a callback set
by another connection object (if the file desriptor was closed by psycopg2 when
an error occurred, and then opened again for a new connection).

The effect of this was, when making tens of parallel connections, an error in
one of them made another time out.

Now, if a psycopg2 error occurs, and the file descriptor has gone bad, the
callback is removed immediately, and the aiopg connection object 'forgets'
about this file descriptor (self._fileno = None), and doesn't try to remove
callbacks in .close().

If there were no errors, callbacks are still removed during .close() call.
@coveralls
Copy link

coveralls commented Sep 5, 2016

Coverage Status

Coverage decreased (-0.2%) to 94.538% when pulling 25c8b03 on not-even:fix-removing-reader into a48542b on aio-libs:master.

7 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.538% when pulling 25c8b03 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.538% when pulling 25c8b03 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@coveralls
Copy link

coveralls commented Sep 5, 2016

Coverage Status

Coverage decreased (-0.2%) to 94.538% when pulling 25c8b03 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.538% when pulling 25c8b03 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.538% when pulling 25c8b03 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.538% when pulling 25c8b03 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@coveralls
Copy link

coveralls commented Sep 5, 2016

Coverage Status

Coverage decreased (-0.2%) to 94.538% when pulling 25c8b03 on not-even:fix-removing-reader into a48542b on aio-libs:master.

fcntl.fcntl(self._fileno, fcntl.F_GETFD)
except OSError as os_exc:
if os_exc.errno == errno.EBADF:
try:
Copy link
Member

Choose a reason for hiding this comment

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

with contextlib.suppress(OSError) should be better than another try/except.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Updated

@coveralls
Copy link

coveralls commented Sep 7, 2016

Coverage Status

Coverage decreased (-0.2%) to 94.53% when pulling ad57967 on not-even:fix-removing-reader into a48542b on aio-libs:master.

9 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.53% when pulling ad57967 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.53% when pulling ad57967 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.53% when pulling ad57967 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.53% when pulling ad57967 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.53% when pulling ad57967 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.53% when pulling ad57967 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.53% when pulling ad57967 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.53% when pulling ad57967 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.53% when pulling ad57967 on not-even:fix-removing-reader into a48542b on aio-libs:master.

@asvetlov asvetlov merged commit 7df2e92 into aio-libs:master Sep 8, 2016
@asvetlov
Copy link
Member

asvetlov commented Sep 8, 2016

Thanks!

@not-even not-even deleted the fix-removing-reader branch September 8, 2016 13:47
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.

Connection error occasionally affects another connection
3 participants