SQLSTATE[HY000] [2002] Operation timed out
pstanek
HOBBYOP

6 months ago

in my app ( Symfony + mysql )

I'm having trouble with build. The connection to the database works with the public IP, but something isn't right with the private one. This only happens when migrating the database. The website itself works (possibly with cache, as every build attempt ends the same way).

Can anyone offer any advice?

Starting Container

In ExceptionConverter.php line 101:

An exception occurred in the driver: SQLSTATE[HY000] [2002] Operation timed

out

In Exception.php line 24:

SQLSTATE[HY000] [2002] Operation timed out

In Driver.php line 33:

SQLSTATE[HY000] [2002] Operation timed out

Stopping Container

$10 Bounty

9 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!


pstanek
HOBBYOP

6 months ago

I have a Hobby Plan and I've exceeded $5. Is this possible? Does it renew on December 8th?


6 months ago

If the migration happens during your build step or before your application is actually started and in the deployment stage, you have to use the public URL.

Private networking isn't available during the build step right now.


pstanek
HOBBYOP

6 months ago

That was the only thing that worked. It happened a few days ago... And I wouldn't want to use a public IP here.

Could it be because I used up my $5 Hobby Plan limit?


6 months ago

The errors wouldn't be related to pricing, if anything your services would be turned off in their entirety


pstanek

I have a Hobby Plan and I've exceeded $5\. Is this possible? Does it renew on December 8th?

6 months ago

If you exceed your $5 plan you'll be charged for the resource usage you've incurred past the $5 mark

Your plan and credits renews whenever your billing cycle renews


pstanek

That was the only thing that worked. It happened a few days ago... And I wouldn't want to use a public IP here. Could it be because I used up my $5 Hobby Plan limit?

6 months ago

No, I don't think that's the problem.

On the hobby plan, you get billed for 5$ USD at the minimum. Your first 5$ of usage is free and you're charged for any overage above the 5$ minimum.

On hobby, you should never see services shutting off because of spend unless you explicitly set spend limits somewhere.

Migrations are happening during build

If you are doing your migration during build, I would migrate them to a pre-deploy command.

Pre-deploy commands run in a container with private network access, so they can reach your MySQL service via the private network. So they should work!

Migrations during deployment

Another option is to do your migration as the first operation when your application starts up, so it happens during the deployment step and has access to private networking.

This solves the issue with not having access to private networking during the build, but I would probably just stick to pre-deploy commands.

If you do go this way, I would just add a short 3 second delay to your startup command; I've noticed sometimes Railway's private networking takes a minute to startup.


pstanek
HOBBYOP

6 months ago

i have

railway-predeploy.sh

#!/bin/sh

set -e

if [ -z "$DATABASE_URL" ]; then

echo "DATABASE_URL is not set. Skipping migrations and cache warmup."

exit 0

fi

max_retries=10

sleep_seconds=5

# Debug: show database host (without password)

echo "DATABASE_URL host: $(echo $DATABASE_URL | sed -E 's|://[^:]+:[^@]+@|://***:***@|')"

echo "Waiting for database to become available..."

for i in $(seq 1 $max_retries); do

if php bin/console doctrine:query:sql "SELECT 1" >/dev/null 2>&1; then

echo "Database is available."

break

fi

echo "Database not reachable yet (attempt ${i}/${max_retries}). Retrying in ${sleep_seconds}s..."

sleep "${sleep_seconds}"

done

# If still not reachable after retries, stop gracefully to avoid failing the whole deploy

if ! php bin/console doctrine:query:sql "SELECT 1" >/dev/null 2>&1; then

echo "Database still not reachable after ${max_retries} attempts. Skipping migrations and cache warmup."

exit 0

fi

php bin/console doctrine:migrations:migrate -n

php bin/console cache:clear

php bin/console cache:warmup

----

config

{

"$schema": "https://railway.app/railway.schema.json",

"build": {

"builder": "DOCKERFILE",

"dockerfilePath": "./Dockerfile"

},

"deploy": {

"preDeployCommand": "sh bin/railway-predeploy.sh"

}

}

Prywatny adres IP nie działa

Publiczny adres IP działa

Attachments


pstanek

i have [railway-predeploy.sh](http://railway-predeploy.sh) _#!/bin/sh_ set -e if \[ -z "$DATABASE\_URL" \]; then echo "DATABASE\_URL is not set. Skipping migrations and cache warmup." exit 0 fi max\_retries=10 sleep\_seconds=5 _\# Debug: show database host (without password)_ echo "DATABASE\_URL host: $(echo $DATABASE\_URL | sed -E 's|://\[^:\]+:\[^@\]+@|://\*\*\*:\*\*\*@|')" echo "Waiting for database to become available..." for i in $(seq 1 $max\_retries); do if php bin/console doctrine:query:sql "SELECT 1" >/dev/null 2>&1; then echo "Database is available." break fi echo "Database not reachable yet (attempt ${i}/${max\_retries}). Retrying in ${sleep\_seconds}s..." sleep "${sleep\_seconds}" done _\# If still not reachable after retries, stop gracefully to avoid failing the whole deploy_ if ! php bin/console doctrine:query:sql "SELECT 1" >/dev/null 2>&1; then echo "Database still not reachable after ${max\_retries} attempts. Skipping migrations and cache warmup." exit 0 fi php bin/console doctrine:migrations:migrate -n php bin/console cache:clear php bin/console cache:warmup \---- config { "$schema": "<https://railway.app/railway.schema.json>", "build": { "builder": "DOCKERFILE", "dockerfilePath": "./Dockerfile" }, "deploy": { "preDeployCommand": "sh bin/[railway-predeploy.sh](http://railway-predeploy.sh)" } } Prywatny adres IP nie działa Publiczny adres IP działa

6 months ago

Can you add this to the start of your script:

nslookup mysql.railway.internal

Replace mysql with whatever your actual private URL is for your database.

Does this output an ipv4/ipv6 (A or AAAA) record? I have a feeling that DNS resolution is the problem here somehow.


Welcome!

Sign in to your Railway account to join the conversation.

Loading...