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 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 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 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:

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


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

Thank you very much !

1 Like

Hey @radames thanks for opening up 5432. I’m hoping to use ElasticSearch (9243) and Papertrail logging (45454) for my app. Would it be possible to open up those 2 ports as well in addition to 5432?

the ports 5432, 9200 and 45454 are now open

Sorry my apologies I mean 9243 not 9200. I believe that’s the port Elastic uses. Thanks so much!

I see, I guess the default ES port is 9200 and it’s been open already, could you change it on your app?

Ah we’re running our app on and that’s the port they gave us unfortunately. I think it might be quite tricky for us to change the port, it’ll also have a bit of downstream impact on all our other services which we’d have to factor in.

hi @kmfoda , the requested ports are open now, please try it again. Thanks

Hi @radames, amazing that worked now! Thank you very much for your help!

1 Like