errors

Connection refused — listener or active rejection

ECONNREFUSED indicates a connection attempt was rejected; a missing listener or an active reject can cause it. Verify protocol, address family, destination address and port; a listener bound to loopback does not automatically accept remote connections. Inspect listener state in the correct network namespace and application logs. Correct the endpoint or start the intended service after configuration checks; if a firewall intentionally rejects traffic, request only the required authorized rule, never disable filtering. Verify connection and application-level readiness from the intended client. Restore prior binding/configuration if a change breaks other clients; maintain console access for network changes. Prevent through health checks and documented listening addresses. The lab binds a private Unix-domain socket without listening, then reproduces ECONNREFUSED and enables listening before a successful local connect. This demonstrates refusal, not a TCP firewall test. Example prerequisites: Linux, Bash, Python 3. Run as a non-root user in a private temporary working directory. Example scope: native exact error. Expected output: Connection refused; listening endpoint accepts connection. No system configuration changes.

Formal Syntax & Structure

linux syntaxlinux
ss -ltn; inspect service status and logs; test authorized endpoint

Parameters & Attributes

NameTypeDescription
ss -ltndiagnostic evidenceTCP listening sockets in current namespace.
address/portdiagnostic evidenceExact intended endpoint.
service logsdiagnostic evidenceListener startup failures.

Return Value

Diagnostic observation

Expected normalized laboratory result: Connection refused; listening endpoint accepts connection. A passing fixture does not prove that a live incident has the same cause.

Working Example

Example Snippetlinux
python3 - <<'PY'import errno, socket, tempfile, oswith tempfile.TemporaryDirectory() as d:    path=os.path.join(d,'endpoint')    with socket.socket(socket.AF_UNIX,socket.SOCK_STREAM) as server:        server.settimeout(1); server.bind(path)        with socket.socket(socket.AF_UNIX,socket.SOCK_STREAM) as client:            client.settimeout(1)            try: client.connect(path)            except OSError as e: assert e.errno==errno.ECONNREFUSED            else: raise AssertionError('refusal expected')        server.listen(1)        with socket.socket(socket.AF_UNIX,socket.SOCK_STREAM) as client:            client.settimeout(1); client.connect(path)            peer,_=server.accept()            with peer: passprint('Connection refused; listening endpoint accepts connection')PY
Linux Reference