frontend service works, database service works but backend service hangs
zkhan122
FREEOP

6 months ago

Hi.

My Spring Boot backend service consistently fails to connect to my custom MySQL service with java.net.SocketTimeoutException: Connect timed outsuch that the backend gets stuck at "HikariPool-1 - Starting..." and never fully starts.

I am using:

Backend: Spring Boot app using custom Docker image, port 8080

MySQL: Custom Docker image based on mysql:8.0, port 3306 (Working no errors)

Frontend: React/nginx, working correctly (can display frontend)

MySQL Service:

Shows that it starts successfully and shows "ready for connections" in logs

  • Has public domain generated: {RETRACTED}-mysql-production.up.railway.app

  • Environment variables set correctly (MYSQL_ROOT_PASSWORD, MYSQL_DATABASE, etc.)

Backend Connection String:

jdbc:mysql://{RETRACTED-mysql-production.up.railway.app:3306/RETRACTED?useSSL=false&allowPublicKeyRetrieval=true

I have tried

  • public domain and internal .railway.internal hostnames

  • Different connection parameters (timeouts, SSL settings)

  • Switched from MySQL 9.4.0 to MySQL 8.0

  • Verified MySQL service is running and accepting connections

so how can I fix this connection between the backend and database services?

Attachments

Solved$10 Bounty

5 Replies

Railway
BOT

6 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


zkhan122
FREEOP

6 months ago

Ok thanks that worked!

Finally would you happen to know why my HTTP requests such as POST are now GET requests with HTTP code 301 ?

I tried adding these settings to application.properties in springboot:

server.forward-headers-strategy=framework
server.tomcat.remoteip.remote-ip-header=x-forwarded-for
server.tomcat.remoteip.protocol-header=x-forwarded-proto
server.tomcat.remoteip.protocol-header-https-value=https

server.tomcat.internal-proxies=.*
server.ssl.enabled=false

additionally I set the allowed origins to : config.setAllowedOrigins(List.of("http://localhost:3000", "http://localhost", "https://{RETRACTED}-frontend-production.up.railway.app", "https://*.railway.app"));

I have also included a screenshot of the requests which chows the NS_ERROR_REDIRECT_LOOP response possibly due to HTTP -> HTTPS redirection attempts?


zkhan122
FREEOP

6 months ago

Here is that screenshot for NS_ERROR_REDIRECT_LOOP as well as showing HTTP code 301 where GET should be POST

Attachments


Status changed to Solved noahd 6 months ago


zkhan122

Here is that screenshot for NS_ERROR_REDIRECT_LOOP as well as showing HTTP code 301 where GET should be POST

zkhan122
FREEOP

6 months ago

fixed by using the correct urls...


Status changed to Awaiting Railway Response Railway 6 months ago


6 months ago

Going to resolve this since it seems like you managed to get it working?


Status changed to Awaiting User Response Railway 6 months ago


Status changed to Solved ray-chen 6 months ago


Loading...