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

Timed out statements raises poor exception content #537

Closed
gmiejski opened this issue Feb 5, 2019 · 3 comments
Closed

Timed out statements raises poor exception content #537

gmiejski opened this issue Feb 5, 2019 · 3 comments
Labels

Comments

@gmiejski
Copy link

gmiejski commented Feb 5, 2019

Versions:

aiopg==0.16.0
psycopg2==2.7.7

When statement gets cancelled after setting a timeout, only a coroutine CancelledError is raised without any context. I would expect some more information why the query has been cancelled:

Reproduce:

import asyncio

from aiopg.sa import create_engine


def create_eng():
    engine = create_engine(
        "postgresql://postgres:postgres@localhost:5432/postgres?sslmode=disable",
        options="-c statement_timeout={}".format(1000),
    )
    loop = asyncio.get_event_loop()
    engine = loop.run_until_complete(engine)
    return engine


async def main(engine):
    async with engine.acquire() as conn:
        async with conn.execute("SELECT * FROM pg_sleep(5)") as result:
            rows = await result.fetchall()
            print(rows)


asyncio.get_event_loop().run_until_complete((main(create_eng())))

Expected output:

any message saying that execute statement timed out

Actual output:

Traceback (most recent call last):
  File "aiopg_timeout_minimal_example.py", line 23, in <module>
      asyncio.get_event_loop().run_until_complete((main(create_eng())))
  File "/lib/python3.7/asyncio/base_events.py", line 573, in run_until_complete
      return future.result()
concurrent.futures._base.CancelledError
@gmiejski gmiejski changed the title Timed out statements raises poor exception Timed out statements raises poor exception content Feb 5, 2019
@aio-libs-bot
Copy link

GitMate.io thinks possibly related issues are #65 (Closing connection object throws exception), #67 (Queries start failing after some time), #9 (Publish psycopg2 exceptions in aiopg module), #78 (SQL statements logging), and #110 (Exception in Connection.del when database connection has failed.).

@vir-mir
Copy link
Member

vir-mir commented Feb 9, 2019

@gmiejski Hi.
unfortunately CanceledError does not support extended traceback. You can read it here and here.

But I think. We can add loop.call_exception_handler which can be overridden with loop.set_exception_handler and with the help of the standard python logger, you can send errors in sentry... the here

@Pliner
Copy link
Member

Pliner commented Dec 5, 2020

Resolved by #537

@Pliner Pliner closed this as completed Dec 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants