Web Development

n8n ECONNREFUSED vs timeout: fix connections safely

Learn to distinguish n8n ECONNREFUSED from a timeout, test DNS, TCP, and HTTP from the failing runtime, and fix the right layer safely.

n8n HTTP Request node diagnosing connection refusal vs timeout
n8n HTTP Request node diagnosing connection refusal vs timeout

ECONNREFUSED means TCP reached an address, but no service accepted the requested port. A connection timeout means n8n received no reply within the wait period. Save the original error and execution environment. Then test DNS, TCP, and HTTP from the exact container, pod, host, or queue worker involved. Change only the layer those tests support. Verify the real n8n node without masking the cause with retries, longer timeouts, or disabled TLS checks.

Is n8n being refused, or is it waiting for a reply?

The error type chooses the first test, but it doesn't identify the final cause. A refusal often means a wrong port, stopped service, or listener on another interface. A timeout more often involves filtering, routing, proxy behavior, egress rules, or a target that accepts traffic without replying.

SymptomLikely layerFirst safe test
ECONNREFUSEDTCP reached an address, but no process accepted the portTest the exact host and port with nc
Connection timeoutPackets or replies are delayed, filtered, or lostTest DNS, then TCP with a bounded timeout
ENOTFOUND or a DNS errorThe hostname cannot be resolvedRun a DNS lookup in the n8n runtime
TLS or certificate errorTCP and usually HTTP reached the target, but TLS validation failedCheck the protocol, certificate name, and trust chain
HTTP 401, 403, or 404The network path works; the application rejected the requestCheck credentials, path, method, and proxy routing

Before changing the node, save the complete original error, timestamp, workflow and execution IDs, node name, exact URL, hostname, port, protocol, and HTTP method. Record whether the execution used the main n8n process, a Docker container, a Kubernetes pod, or a queue-mode worker. Keep tokens and authorization headers out of screenshots and command output.

A refusal suggests that the route may have reached the destination, but nothing is listening on that port. A timeout has several possible causes. Don't mask either symptom with retries, a much longer timeout, or disabled TLS verification before you understand the failure.

Before you start: confirm the destination and execution environment

First confirm the destination n8n actually uses. Don't rely on the URL you remember configuring. Inspect the HTTP Request node, URL-building expressions, credentials, and proxy settings. These details determine where the request runs and which path it takes.

Write down:

  • The final protocol, such as http or https.
  • The hostname and port, including non-default ports.
  • The path and method.
  • Proxy-related node options and HTTP_PROXY, HTTPS_PROXY, or ALL_PROXY environment variables. These can change the outbound route.
  • The runtime that executed the request and its network attachments.

localhost means the current network namespace. It doesn't automatically mean the machine running n8n. In Docker, localhost inside the n8n container normally points back to that container. In Docker Compose, another service is usually reached by its Compose service name on the shared Docker network. In Kubernetes, use the appropriate Kubernetes Service DNS name and port. Don't assume the node or pod address.

If n8n uses queue mode, inspect the worker that ran the failed job. The main process and worker can have different DNS, routes, environment variables, proxy settings, or network attachments. Run the checks from the worker, not only from the n8n editor or host.

Stop if the final URL, execution runtime, or original error is unclear. Those details decide whether to test DNS, TCP, HTTP, a proxy, or the application.

Run DNS, TCP, and HTTP tests from the n8n runtime

Run every check inside the failing container or pod. If n8n runs directly on a host or worker, use that system instead. A laptop or Docker host can have different DNS, routes, proxy settings, and firewall treatment, so its successful test doesn't validate the n8n runtime.

  1. Open a shell in the runtime that made the request. Use the actual container or pod name.
Docker shell
docker exec -it <n8n-container> sh
Kubernetes shell
kubectl exec -it <n8n-pod> -- sh

If the image has no shell or diagnostic tools, use a temporary diagnostic container attached to the same network or pod. Follow your platform's current documentation. Don't install packages permanently just to investigate unless that change is approved.

  1. Test DNS for the exact hostname.
DNS lookup
getent hosts <hostname>

If getent isn't available, use nslookup or dig when present. No result means a DNS or hostname problem. A returned address confirms name resolution only. It doesn't show that the port is reachable.

  1. Test the TCP port with a bounded wait.
TCP check
nc -vz -w 5 <hostname> <port>

A successful connection shows that something accepted TCP on that address and port. It doesn't validate the HTTP path, authentication, proxy route, or TLS handshake. A refusal supports a stopped service, wrong port, or listener bound to another interface. A timeout suggests filtering, routing, an egress rule, or a silent intermediary.

  1. Test the configured protocol and path without printing secrets.
HTTP check
curl --connect-timeout 5 --max-time 15 -sS -D - -o /dev/null https://<hostname>:<port>/<path>

Use http:// when that is the configured protocol. A response status shows that the request reached an HTTP-speaking endpoint. A redirect may indicate a reverse proxy. TLS errors show that TCP connected, but certificate, protocol, or trust validation failed. If the earlier checks succeed but this request times out, examine the HTTP server, proxy route, request path, or response handling.

Fix the layer that caused the refusal or timeout

Make one reversible change supported by the evidence. Repeat the same bounded test afterward. Avoid broad firewall changes, permanent retries, and disabled certificate checks as first responses.

  1. For ECONNREFUSED, check the target service's running state, listening interface, and configured port. Compare the n8n URL with the service configuration. If the service is stopped, restore it through the normal deployment process. If the port is wrong, change only the n8n URL or environment value that supplied it. Then rerun the TCP test.

If n8n is in Docker, replace an invalid localhost target with the correct Compose service name when both services share a Docker network. If the target is on the host, use the host address or the platform-supported host gateway for your installation. Don't guess a new port. Confirm it from the service or deployment configuration.

  1. For a timeout, check these items in order: DNS result, destination address, egress rule, firewall rules, proxy requirement, and reverse-proxy route. If outbound traffic must use a proxy, configure the n8n node or approved environment variables instead of bypassing the policy. If a Kubernetes NetworkPolicy blocks egress, make the narrowest policy change for the required destination and port. Then retest.
  2. If TCP succeeds but HTTP fails, inspect the reverse proxy and application route. Nginx, Traefik, Cloudflare, or another intermediary may expose one hostname while forwarding to a different internal service. Confirm the host header, path, method, and upstream health. A 404 or 401 means the network path works; it isn't a connection failure.
  3. If HTTPS reaches the server but TLS validation fails, use the correct hostname and certificate chain. Install the needed trust certificate in the approved runtime or correct the endpoint's certificate. Don't disable TLS verification to make the node pass. That removes the protection you need.

If the same bounded test still fails after one targeted change, stop changing settings and keep the evidence. Repeated edits make the changed layer unclear.

Verify the workflow and record what happened

Verification requires rerunning the same n8n HTTP Request node from the same execution environment. Seeing that the editor loads isn't enough. Repeat the diagnostic checks first. Then run the workflow with the real method, path, credentials, and expected request body.

Confirm that:

  • The execution uses the intended main process or queue worker.
  • The resolved hostname and port are correct for that environment.
  • The node receives the expected HTTP status and response shape.
  • Authentication still works without exposing the credential.
  • A reverse proxy doesn't redirect the request to an unintended host.
  • TLS validation remains enabled.
  • The workflow doesn't depend on a host-only URL that workers can't reach.

For a long-running endpoint, an asynchronous workflow can avoid holding one HTTP connection open throughout the operation. One documented pattern is to accept the request, return a job identifier, and poll or resume later. This is an application-design change, not a replacement for fixing a broken route.

Record the original error and UTC timestamp. Also record the node and execution IDs, runtime identity, URL with secrets removed, DNS result, resolved address, TCP result, HTTP status or bounded timeout, proxy involvement, and exact reversible change. If you need escalation, include the remaining error and say whether the failure occurred only on workers, only through a proxy, or only in one environment.

Conclusion

Run the checks from the runtime that failed. Change only the layer supported by the evidence, then rerun the actual n8n node. If the bounded test still fails, roll back the targeted change and escalate with the recorded execution details instead of masking the problem.

Frequently Asked Questions

Why does localhost cause ECONNREFUSED in n8n Docker setups?

localhost usually points to the n8n container itself, not the host or another service. The request can therefore reach a network namespace where nothing listens on that port. Use the target service name on the shared Docker network, or the approved host gateway when the service runs on the host. Confirm the choice with a TCP test from the n8n container.

Does a successful nc test prove that the n8n HTTP Request node will work?

No. nc confirms only that TCP connected to an address and port. The HTTP path, method, credentials, proxy route, response behavior, and TLS certificate can still fail. Follow it with a bounded curl request using the same protocol and hostname. Then run the actual n8n node.

Why can the Docker host reach an API while n8n cannot?

The host and n8n container may use different DNS settings, routes, firewall treatment, proxy variables, or network attachments. Queue mode can create the same difference between the worker and main process. Run the checks from the container or worker that executed the workflow.

Sources

Cloud & Routing Desk

Think Tech Editorial

Troubleshooting guides for reverse proxies, TLS routing, and self-hosted PaaS deployments.