-
Notifications
You must be signed in to change notification settings - Fork 85
fix: error on connect_async() event loop mismatch #1113
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
Conversation
d742686 to
dc2212a
Compare
kgala2
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
|
i think this check is too restrictive and breaks my FastAPI application that uses SQLAlchemy and asyncpg. maybe it's better to track the loop ids instead of comparing the objects. here's a stack trace: |
|
I did some research, and I have an alternate explanation: Your application likely has more than one event loop. The code in the connector here correctly compares event loops. There is no possibility that the same asyncio event loop can be represented by two distinct loop objects. Here's the evidence from your stack trace that your app has more than one event loop: The first loop is runs the FastAPI router and the Cloud SQL Connector. This is the current loop when your application logs this message: "cloud_sql.py:116] [CLOUD_SQL] connect_async called from loop 5503254560, Connector was created in loop 550325456". Then, the code calls the SQLAlchemy code |
|
@hessjcg where are you seeing that in the log I sent? I think there's a mistake/some clipping of the text because the log says "cloud_sql.py:116] [CLOUD_SQL] connect_async called from loop 5503254560, Connector was created in loop 5503254560" not "cloud_sql.py:116] [CLOUD_SQL] connect_async called from loop 5503254560, Connector was created in loop 550325456".
|

Today, the Python Connector for async usage does not allow being called across
multiple event loops.
However, we do not explicitly define that logic nor make it clear via an error message.
This PR adds an error message to check in
connect_asyncif theConnector._loopattribute matches the current running event loop and errors if it does not (multiple event loops).
Related to #1107