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

Guard against improper use-after-release of connection resources #190

Closed
elprans opened this issue Sep 11, 2017 · 1 comment
Closed

Guard against improper use-after-release of connection resources #190

elprans opened this issue Sep 11, 2017 · 1 comment
Assignees

Comments

@elprans
Copy link
Member

elprans commented Sep 11, 2017

The below seems to be a common (incorrect) pattern of use:

async with pool.acquire() as conn:
    # await conn.add_listener
    # await conn.prepare
    # etc

# Incorrect assumption that the listeners and prepared statements would continue to 
# work beyond the `conn` acquisition context

See #189 for an example issue.

To give a better hint that this is not a valid thing to do, we should check if conn has unclosed resources on it before releasing it. Possibly, behind a debug flag (either ASYNCPGDEBUG, or PYTHONASYNCIODEBUG, or both).

@elprans elprans self-assigned this Sep 11, 2017
@elprans elprans changed the title Issue a Warning whenever a connection with unclosed resources is released to a pool Guard against improper use-after-release of connection resources Sep 11, 2017
@elprans
Copy link
Member Author

elprans commented Sep 11, 2017

For prepared statements and cursors we want an InterfaceError to be raised, just like when an improper call to a connection method is made.

elprans added a commit that referenced this issue Sep 12, 2017
We already check for attempts to use connection methods after the
connection has been returned to the pool.  This adds a similar check
for objects associated with the connection: prepared statements and
cursors.

Issue: #190.
elprans added a commit that referenced this issue Sep 12, 2017
We already check for attempts to use connection methods after the
connection has been returned to the pool.  This adds a similar check
for objects associated with the connection: prepared statements and
cursors.

Issue: #190.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant