8 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.internalhostnames - 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
5 Replies
8 months ago
Hey there! We've found the following might help you get unblocked faster:
- 🧵 I can't connect Redis to Ktor server
- 🧵 HashiCorp Vault - Connect timed out
- [🧵 Unable to acquire JDBC Connection HikariPool-1 - Connection is not available, request timed out - PostgreSQL
If you find the answer from one of these, please let us know by solving the thread!
8 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=falseadditionally I set the allowed origins to : config.setAllowedOrigins(List.of("http://localhost:3000", "http://localhost", "https://{RETRACTED}-frontend-production.up.railway.app", "https://%2A.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?
8 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 • 8 months ago
zkhan122
Here is that screenshot for NS\_ERROR\_REDIRECT\_LOOP as well as showing HTTP code 301 where GET should be POST
8 months ago
fixed by using the correct urls...
Status changed to Awaiting Railway Response Railway • 8 months ago
8 months ago
Going to resolve this since it seems like you managed to get it working?
Status changed to Awaiting User Response Railway • 8 months ago
Status changed to Solved ray-chen • 8 months ago