How to fix Error: EHOSTDOWN: host is down in Node.js

Node.jsINTERMEDIATEHIGHUpdated Dec 9, 2025ยท 181 views

EHOSTDOWN is a socket connection error indicating the remote host is down or unreachable at the network layer. This error occurs when Node.js receives status information from the underlying communication services that the target host is down.

Quick fix

Fixes EHOSTDOWN

# Ping the target host
ping example.com

# Check TCP connectivity on the specific port
telnet example.com 80

# Or use nc (netcat)
nc -zv example.com 80
  1. Verify the target host is online and accessible
  2. Add proper error handling for network operations
  3. Check AWS credentials if using AWS SDK
  4. Implement retry logic with exponential backoff
node.js โ€” error
# Ping the target host
ping example.com
# Check TCP connectivity on the specific port
telnet example.com 80
# Or use nc (netcat)
nc -zv example.com 80
Error: EHOSTDOWN: host is down

What this error means

EHOSTDOWN is a low-level network error that originates from the operating system's socket layer. It indicates that the remote host you're trying to connect to is down according to information received from the underlying communication services. This error is distinct from EHOSTUNREACH (no route to host) - EHOSTDOWN specifically means the host itself is down, not that there's no network path to reach it. The error typically occurs when making HTTP requests, connecting to databases, or establishing any TCP/socket connection where the target system is unavailable. In Node.js, this error can manifest in various contexts including HTTP requests, database connections, Redis clients, and AWS SDK operations. Sometimes the error message can be misleading - for example, AWS SDK may show EHOSTDOWN when the actual issue is expired credentials rather than network connectivity.

Typical symptoms

  • Network requests fail with 'Error: connect EHOSTDOWN' message
  • Application cannot establish connections to remote services
  • HTTP client operations throw unhandled EHOSTDOWN errors
  • Database or cache connections fail at startup
  • AWS SDK operations fail with EHOSTDOWN and IP 169.254.169.254
  • Previously working network connections suddenly fail

Common causes

  1. Target server or host is actually powered off or crashed
  2. Target host lost network connectivity (interface down, cable unplugged)
  3. Firewall or network device blocking connection and reporting host down
  4. Layer 2 connectivity issue (no ARP response from directly connected host)
  5. AWS credentials expired or SSO session timed out (misleading error)
  6. Incorrect hostname or IP address resolving to unreachable host
  7. Network routing changes making host appear down
  8. Container or VM host experiencing issues

How to fix "Error: EHOSTDOWN: host is down"

1Verify the target host is online and accessible

First, check if the target host is actually reachable using basic network tools:

bash
# Ping the target host
ping example.com

# Check TCP connectivity on the specific port
telnet example.com 80

# Or use nc (netcat)
nc -zv example.com 80

If these commands fail, the host may genuinely be down or unreachable from your network.

2Add proper error handling for network operations

Implement error handling to catch EHOSTDOWN errors gracefully:

javascript
const http = require('http');

const options = {
  hostname: 'example.com',
  port: 80,
  path: '/',
  method: 'GET'
};

const req = http.request(options, (res) => {
  // Handle response
});

req.on('error', (err) => {
  if (err.code === 'EHOSTDOWN') {
    console.error('Host is down:', err.message);
    // Implement retry logic or fallback
  } else {
    console.error('Request error:', err);
  }
});

req.end();

For promise-based code with axios or fetch, use try-catch:

javascript
const axios = require('axios');

try {
  const response = await axios.get('http://example.com');
} catch (error) {
  if (error.code === 'EHOSTDOWN') {
    console.error('Host is down, retrying with backup server...');
    // Implement fallback logic
  } else {
    throw error;
  }
}
3Check AWS credentials if using AWS SDK

If you see EHOSTDOWN with IP 169.254.169.254 (AWS metadata service), the issue is likely expired credentials rather than network:

bash
# For AWS SSO users, refresh your session
aws sso login --profile your-profile

# Or re-configure credentials
aws configure

In your code, ensure proper credential handling:

javascript
const AWS = require('aws-sdk');

// Explicitly set credentials with error handling
AWS.config.credentials = new AWS.SharedIniFileCredentials({
  profile: 'your-profile'
});

AWS.config.credentials.get((err) => {
  if (err) {
    console.error('Error loading credentials:', err);
  } else {
    console.log('Credentials loaded successfully');
  }
});
4Implement retry logic with exponential backoff

For transient network issues, implement automatic retry with backoff:

javascript
async function fetchWithRetry(url, maxRetries = 3, baseDelay = 1000) {
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
    try {
      const response = await fetch(url);
      return response;
    } catch (error) {
      if (error.code === 'EHOSTDOWN' && attempt < maxRetries) {
        const delay = baseDelay * Math.pow(2, attempt - 1);
        console.log(`Attempt ${attempt} failed, retrying in ${delay}ms...`);
        await new Promise(resolve => setTimeout(resolve, delay));
      } else {
        throw error;
      }
    }
  }
}

// Usage
try {
  const result = await fetchWithRetry('http://example.com/api');
} catch (error) {
  console.error('All retry attempts failed:', error);
}
5Verify firewall and network configuration

Check if firewall rules or network configuration are blocking the connection:

bash
# Check local firewall (Linux)
sudo iptables -L -n

# Check if SELinux is blocking (RHEL/CentOS)
sudo getenforce
sudo ausearch -m avc -ts recent

# Verify DNS resolution
nslookup example.com
dig example.com

# Check routing table
netstat -rn
# or
ip route show

If you're in a corporate environment, check proxy settings:

javascript
// Set proxy for Node.js HTTP requests
const https = require('https');
const HttpsProxyAgent = require('https-proxy-agent');

const agent = new HttpsProxyAgent('http://proxy.company.com:8080');

https.get('https://example.com', { agent }, (res) => {
  // Handle response
});

Advanced notes

Understanding EHOSTDOWN vs EHOSTUNREACH:
EHOSTDOWN specifically indicates the host is down (received from layer 2/3), while EHOSTUNREACH means no route exists to the host. EHOSTDOWN is less common and typically indicates more direct connectivity failure.

Layer 2 Connectivity:
EHOSTDOWN often occurs at layer 2 (data link layer) when a device is directly connected but doesn't respond to ARP requests. This is common in scenarios where a device loses power or its network interface fails.

Misleading AWS SDK Errors:
The AWS SDK may report EHOSTDOWN when trying to reach the metadata service (169.254.169.254) if credentials are expired. This is misleading because the issue isn't network connectivity but authentication. Always check credential status first when seeing this error with AWS services.

Container and Cloud Environments:
In containerized environments (Docker, Kubernetes), EHOSTDOWN can occur when:
- Container networking isn't properly configured
- Service mesh sidecar isn't ready
- Host VM experiences networking issues
- Pod-to-pod networking fails due to CNI plugin issues

Health Checks and Circuit Breakers:
Implement health check mechanisms and circuit breaker patterns to handle hosts that frequently go down:

javascript
const CircuitBreaker = require('opossum');

const options = {
  timeout: 3000, // 3 seconds
  errorThresholdPercentage: 50,
  resetTimeout: 30000 // 30 seconds
};

function makeRequest() {
  return fetch('http://example.com/api');
}

const breaker = new CircuitBreaker(makeRequest, options);

breaker.fallback(() => {
  return { data: 'cached or default data' };
});

breaker.on('open', () => {
  console.log('Circuit breaker opened - too many failures');
});

Monitoring and Alerting:
Log EHOSTDOWN errors with context (timestamp, target host, retry attempts) to help identify patterns. Use structured logging libraries like winston or pino for better observability.

Frequently asked questions

What does "EHOSTDOWN" mean?
EHOSTDOWN is a low-level network error that originates from the operating system's socket layer. It indicates that the remote host you're trying to connect to is down according to information received from the underlying communication services. This error is distinct from EHOSTUNREACH (no route to host) - EHOSTDOWN specifically means the host itself is down, not that there's no network path to reach it.
How do I fix "EHOSTDOWN"?
EHOSTDOWN is a socket connection error indicating the remote host is down or unreachable at the network layer. This error occurs when Node.js receives status information from the underlying communication services that the target host is down.
What causes "EHOSTDOWN"?
Target server or host is actually powered off or crashed Target host lost network connectivity (interface down, cable unplugged) Firewall or network device blocking connection and reporting host down
Is the "EHOSTDOWN" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading