Skip to content

Connection Timeout

Error message

                dial tcp: connect: connection timed out
              

Quick summary

The application cannot reach a remote service within the timeout period, usually due to network issues or the service being down.

Why this happens

  • The target service is down or not listening on the expected port

  • A firewall or security group blocks the connection

  • DNS resolution is slow or returns the wrong IP address

  • The network route is incorrect or the service is in an unreachable network

Minimal example

✗ Broken code
# Application tries to connect to a database that is down
DB_HOST=db.example.com
DB_PORT=5432
# Connection times out after 30s
✓ Fixed code
# Check if database is running first
kubectl get pods -l app=database
# If down, restart it
kubectl rollout restart deployment/database

The database service is down. The fix checks the database Pod status and restarts it if needed.

How to diagnose

  • Test connectivity: curl -v <url> or telnet <host> <port>

  • Check DNS resolution: nslookup <host> or dig <host>

  • Verify the service is running and listening on the correct port

  • Check firewall rules and security groups between the source and destination

How to fix

  • Start or restart the target service if it is down

  • Open the required port in the firewall or security group

  • Fix DNS configuration to resolve to the correct IP

  • Increase the timeout value if the service is slow but eventually responds

How to prevent

  • Use circuit breakers to fail fast instead of waiting for timeouts

  • Monitor service health and alert on connection failures

  • Document network topology and required ports

Related Resources

Related Glossary

← Back to language