Skip to content

Leaked Connections should close socket #323

Closed
@percontation

Description

@percontation
  • asyncpg version: 0.17.0.dev0+78ea13a
  • PostgreSQL version: 10.4 (Debian 10.4-2.pgdg90+1)
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : It's a docker postgres:latest
  • Python version: 3.6.5
  • Platform: OS X 10.11.6
  • Do you use pgbouncer?: no
  • Did you install asyncpg with pip?: yes (but github, not pypi)
  • If you built asyncpg locally, which version of Cython did you use?: 0.28.2
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : yes

In the face of timeouts/other exceptions, it may not always be possible to have a reference to a Connection (that was successfully initiated) and call .close() on it. So, leaked Connections should clean up after themselves. For example, running asyncio.get_event_loop().run_until_complete(asyncpg.connect("postgres://postgres:postgres@localhost/postgres")) seems to leave the socket open forever (at least on my platform).

When attempting to address this, I noticed a couple of things that may or may not be related bugs:

  1. Connection.terminate() seems to not close the socket, and also leave it open forever.
  2. Connection and its associated Protocol never seem to get garbage collected after calling .terminate() (or getting leaked); my guess is that it has something to do with the underlying _SelectorSocketTransport not getting GCed, but I'm not confident about what's happening here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions