Open port for space to connect to PostgreSQL

Hi @chris-rannou,

Could you open the port 5432 for this space: Defi Ai 2022 - a Hugging Face Space by vnghia as I need to connect to a PostgreSQL database ?

Thank you very much !

hi @vnghia are you sure your DB service is running at 34.155.175.170:5432? if you’re trying to access the DB from space, you don’t need that port to be open, however on your Space log it states timeout trying to reach your db server

Hi @radames, I am quite sure my DB service is running at 34.155.175.170:5432 because the same code works on my machine. It is a Google Cloud SQL instance (I already opened the DB to every IP and port by 0.0.0.0/0 on GCP side), maybe that is the reason why I have this error ?

ok you’re right, you might need outgoing port access, currently only 80 and 443, we’ll get back to you soon.

1 Like

Hi @vnghia,

Port 5432 is now open.

1 Like

hmmm, unfortuntately, I still can not access to my DB instance. I also add a command to check if the DB is ready by pg_isready. And I found that when building the image, the connection is fine, but it failed while the space is running.

You can see the log here: Defi Ai 2022 - a Hugging Face Space by vnghia

Do the port need to be opened twice for building and running or there is something else ?

Hi @vnghia ,

I had a similar issue when integrating my Hugging Face Space with my AWS instance.
I later found that Hugging Face Space only approves for the privileged port, which is below 1024.
I think this is for security reason, and I suggest that you change your SQL server port open with privileged port.

For now, I switched the service port to 80, but I remembered that it is fine if the port number is below 1024.

Ref for my previous issue:

Hi @deepkyu I dont think so because @chris-rannou has already opened the port and my code can connect to the database while building the Docker image but not while running. I am suspecting there are some bugs with the Docker space :confused:

@vnghia
Oh I see. that’s also one of weird situations…

From my experience, I concluded that there were some outbound policies in Hugging Face Space server which blocks unprivileged ports. At that time, my docker container at my AWS instance communicates well from other servers’ request except the HF Space.

I’m sorry for not being helpful tho.
Hope it works out :+1:

1 Like

hi @vnghia and @deepkyu , we’ve changed the rules and we’ll enable 5432, 27017 in addition to 80, 443. Sorry @vnghia I don’t think it’s in prod yet. I’ll ping you here. Thanks

2 Likes

hi @vnghia it should be fixed now, thanks for the patience

Thank you very much !

1 Like