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

"TimeoutError: [Errno 110] Connection timed out" from Google Colab Notebook #368

Closed
natemurthy opened this issue Aug 28, 2024 · 4 comments · Fixed by #369 or #370
Closed

"TimeoutError: [Errno 110] Connection timed out" from Google Colab Notebook #368

natemurthy opened this issue Aug 28, 2024 · 4 comments · Fixed by #369 or #370
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: cleanup An internal cleanup or hygiene concern. type: docs Improvement to the documentation for an API.

Comments

@natemurthy
Copy link

natemurthy commented Aug 28, 2024

Bug Description

I am trying to connect to a trial AlloyDB instance from a Google Colab Notebook. Both the my Notebook / GDrive are managed under the same GCP organization as the DB instance. Unfortunately I observe a timeout (already have my ADC with correct database user credentials, password hidden). The code I'm evaluating is available here: https://colab.research.google.com/drive/1_Xd4rfncFBfxbgQwYu_ZL4Tu76VApcn2#scrollTo=MA7sOm6qF2b0

from google.cloud.alloydb.connector import Connector

connector = Connector()

# https://github.com/GoogleCloudPlatform/alloydb-python-connector/tree/main
conn = connector.connect(
    "projects/dynamic-branch-380821/locations/us-central1/clusters/tmp-trial-alloydb-cluster/instances/primary-instance",
    "pg8000",
    user="analyst",
    password=db_password,
    db="verse-db"
)

The timeout occurs in the connecter.connect() method.

Example code (or command)

No response

Stacktrace

TimeoutError                              Traceback (most recent call last)
<ipython-input-12-ecf23c99c5ae> in <cell line: 6>()
      4 
      5 # https://github.com/GoogleCloudPlatform/alloydb-python-connector/tree/main
----> 6 conn = connector.connect(
      7     "projects/dynamic-branch-380821/locations/us-central1/clusters/tmp-trial-alloydb-cluster/instances/primary-instance",
      8     "pg8000",

7 frames
/usr/lib/python3.10/socket.py in create_connection(address, timeout, source_address)
    831             if source_address:
    832                 sock.bind(source_address)
--> 833             sock.connect(sa)
    834             # Break explicitly a reference cycle
    835             err = None

TimeoutError: [Errno 110] Connection timed out

Steps to reproduce?

To reproduce, just copy the notebook and execute within your GCP+Gdrive/Colab environment

Environment

This is already documented in the notebook

Additional Details

No response

@natemurthy natemurthy added the type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. label Aug 28, 2024
@enocom enocom assigned enocom and unassigned nancynh Aug 29, 2024
@enocom enocom added priority: p2 Moderately-important priority. Fix may not be included in next release. type: question Request for information or clarification. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Aug 29, 2024
@enocom
Copy link
Member

enocom commented Aug 29, 2024

By default the Python Connector tries to connect with private IP. Unless the VM that runs your notebook code is within the same VPC as your PSA attachment, you'll need to update your instance to have a public IP and update your connector code to be:

# https://github.com/GoogleCloudPlatform/alloydb-python-connector/tree/main
conn = connector.connect(
    "projects/dynamic-branch-380821/locations/us-central1/clusters/tmp-trial-alloydb-cluster/instances/primary-instance",
    "pg8000",
    user="analyst",
    password=db_password,
    db="verse-db",
    ip_type="PUBLIC",
)

The reason you're seeing a timeout error is there's no network path between the machine running your notebook and your private IP address.

@enocom
Copy link
Member

enocom commented Aug 29, 2024

You can assign a public IP with:

!gcloud beta alloydb instances update {instance_name} --region={region} --cluster={cluster_name} --assign-inbound-public-ip=ASSIGN_IPV4

@natemurthy
Copy link
Author

natemurthy commented Aug 30, 2024

Cool, that worked! Maybe that detail above can be added to the top-level README? I noticed for the cloud-sql-python-connector["pg8000"] library the Connector.connect() by default used the public IP. So that might be a small thing that should be consistent between the two class methods.

@enocom
Copy link
Member

enocom commented Aug 30, 2024

Glad to hear it and good idea. I've sent a PR to update the README to make this clear.

@enocom enocom added type: docs Improvement to the documentation for an API. type: cleanup An internal cleanup or hygiene concern. and removed type: question Request for information or clarification. labels Aug 30, 2024
@enocom enocom closed this as completed in 1d8a9a6 Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: cleanup An internal cleanup or hygiene concern. type: docs Improvement to the documentation for an API.
Projects
None yet
3 participants