-
Notifications
You must be signed in to change notification settings - Fork 6
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
(pg8000.exceptions.InterfaceError) on cloud run for AlloyDB connections #322
Comments
I am trying to refer following to see if it is a solution GoogleCloudPlatform/cloud-sql-python-connector#1093 TypeError: connect() got an unexpected keyword argument 'refresh_strategy' from google.cloud.alloydb.connector import Connector, IPTypes def get_engine(): |
Yes, this looks like a case of needing lazy refresh. We'll be porting GoogleCloudPlatform/cloud-sql-python-connector#1093 here soon. In the meantime, you have two workarounds:
|
Tracking issue is here: #298 |
In that case, please show me how you're connecting in Python. |
I have a database.py file with following code
in my api routes i am using get_db
|
The argument passed to Try something like this instead: import sqlalchemy
from google.cloud.alloydb.connector import Connector, IPTypes
import pg8000
def get_engine(connector: Connector) -> sqlalchemy.engine.base.Engine:
def getconn() -> pg8000.dbapi.Connection:
return connector.connect(
"<INSTANCE_URI>",
"pg8000",
user=DB_USER,
password=DB_PASS,
db=DB_NAME,
ip_type=IPTypes.PUBLIC,
)
return sqlalchemy.create_engine(
"postgresql+pg8000://",
creator = getconn,
) You'll want to save a reference to the Connector to close it when your app shuts down too. |
With my previous code, it failed with same behavior on compute engine. I have updated your reference code and following is the logger print. So far it is working great on compute engine with the change. Thank you for your quick response.
|
Closing. As resolved. |
Glad to hear it. We'll be shipping lazy refresh soon as well, so if you see problems in Cloud Run, we can discuss in #298. |
Bug Description
On cloud run with all network steps everything followed the connector is able to make connection with database for 10-15 minutes and returns 200 OK api responses, after that it just throws below error leading to 500 internal server error on cloud run.
Example code (or command)
No response
Stacktrace
Steps to reproduce?
...
Environment
Additional Details
No response
The text was updated successfully, but these errors were encountered: