The Node socket's connect event tells you that TCP reached the proxy. It does not say that the proxy has opened a connection to the destination.

A SOCKS5 server expects method negotiation, any selected authentication, and a destination request before application traffic. Sending an HTTP request immediately can make the server close the connection. A later write can then produce EPIPE.

EPIPE alone does not prove a missing handshake. It reports a write to a connection whose peer is no longer accepting that communication. Read the earlier events and protocol replies to find out why the peer closed.

Use a connector that implements the complete SOCKS exchange. For Node's core HTTPS client, a SOCKS-aware agent can perform that negotiation before destination TLS. If implementing the exchange yourself, accumulate data according to the protocol's field lengths. One data event is not guaranteed to contain one complete reply, and the returned bound address need not match one hard-coded byte string.

Register error handling before the operation can fail, retain the connection stage in the error report, and send the destination protocol only after negotiation succeeds. Catching the error prevents an unhandled event; it does not repair an invalid exchange.

Artihkkalat mat laktásit