🔧 Error Fixes
· 2 min read

Connection Timeout — How to Fix It


Error: connect ETIMEDOUT 10.0.0.1:5432
TimeoutError: Connection timed out
requests.exceptions.ConnectTimeout

Your app tried to connect to something and it didn’t respond in time. The server is either down, unreachable, or too slow.

Fix 1: Check if the Server Is Running

# Can you reach it at all?
ping 10.0.0.1

# Is the port open?
nc -zv 10.0.0.1 5432

# Check if the service is running
systemctl status postgresql

Fix 2: Wrong Host or Port

# ❌ Common mistakes
DATABASE_URL=postgresql://localhost:5432/mydb  # Wrong if DB is remote
API_URL=http://api.example.com:3000            # Wrong port

# ✅ Verify the actual host and port
# Check your .env, config files, or cloud dashboard

Fix 3: Firewall Blocking the Connection

# Check if a firewall is blocking outbound traffic
sudo iptables -L -n | grep 5432

# AWS: check Security Group inbound rules
# GCP: check Firewall rules
# Azure: check NSG rules

# Allow the port
sudo ufw allow 5432

Fix 4: DNS Resolution Failing

# Can the hostname resolve?
nslookup api.example.com
dig api.example.com

# If DNS fails, try the IP directly
curl -v http://10.0.0.1:3000

Fix 5: Increase Timeout Duration

// Node.js — increase timeout
const axios = require('axios');
axios.get('https://api.example.com', { timeout: 30000 });  // 30 seconds

// Python
import requests
requests.get('https://api.example.com', timeout=30)
# Database connection timeout
# PostgreSQL
psycopg2.connect(host='...', connect_timeout=10)

# MySQL
mysql.connector.connect(connection_timeout=10)

Fix 6: Connection Pool Exhausted

// ❌ Too many connections, new ones time out waiting
// Check your pool settings
const pool = new Pool({
    max: 20,              // Increase if needed
    connectionTimeoutMillis: 5000,
    idleTimeoutMillis: 30000,
});

Debugging Checklist

# 1. Can you reach the host?
ping hostname

# 2. Is the port open?
nc -zv hostname port

# 3. Is it a DNS issue?
nslookup hostname

# 4. Is it a firewall issue?
traceroute hostname

# 5. Is the server overloaded?
# Check server CPU, memory, connection count