Skip to content

Conversation

elprans
Copy link
Member

@elprans elprans commented Nov 2, 2017

Connection.close() and Pool.release() each gained the new timeout
parameter. The pool.acquire() context manager now applies the
passed timeout to __aexit__() as well.

Connection.close() is now actually graceful. Instead of simply dropping
the connection, it attempts to cancel the running query (if any), asks
the server to terminate the connection and waits for the connection to
terminate.

To test all this properly, implement a TCP proxy, which emulates sudden
connectivity loss (i.e. packets not reaching the server).

Closes: #220

@elprans elprans requested a review from 1st1 November 2, 2017 21:33
@elprans elprans force-pushed the timeouts branch 2 times, most recently from 2dcfa46 to dcb3816 Compare November 4, 2017 19:37
else:
try:
await self._con.reset()
budget = timeout
Copy link
Member

Choose a reason for hiding this comment

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

Handle when timeout is None

self._request_cancel()
# Make asyncio shut up about unretrieved
# QueryCanceledError
waiter.add_done_callback(lambda f: f.exception())
Copy link
Member

Choose a reason for hiding this comment

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

Please make sure you have a warning here, as we fixed that stale cancellation exception warning in 3.6.2

Copy link
Member Author

@elprans elprans Nov 6, 2017

Choose a reason for hiding this comment

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

This is actually not about the asyncio.CancelledError, this is asyncpg.QueryCanceledError, which now propagates when an operation is cancelled.

self._con._protocol._wait_for_cancellation(),
timeout, loop=self._pool._loop)
budget -= time.monotonic() - started
if budget is not None:
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test that would fail without this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

When running against a temporary cluster, make sure the default
superuser and database name are 'postgres'.

When PGHOST environment variable is specified, rely on the default
connection spec heuristics.
Connection.close() and Pool.release() each gained the new timeout
parameter.  The pool.acquire() context manager now applies the
passed timeout to __aexit__() as well.

Connection.close() is now actually graceful.  Instead of simply dropping
the connection, it attempts to cancel the running query (if any), asks
the server to terminate the connection and waits for the connection to
terminate.

To test all this properly, implement a TCP proxy, which emulates sudden
connectivity loss (i.e. packets not reaching the server).

Closes: #220
@elprans elprans merged commit bdfdd89 into master Nov 15, 2017
@elprans elprans deleted the timeouts branch November 15, 2017 20:05
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 not being returned to the pool after connection loss

2 participants