{"record":{"id":"8e5021bfd446da82","repo":"ginuerzh/gost","slug":"bind-peer-connect-failure","errorCode":null,"errorMessage":"bind: peer connect failure","messagePattern":"bind: peer connect failure","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"socks.go","lineNumber":2001,"sourceCode":"}\n\n// Handshake waits for a peer to connect to the bind port.\nfunc (c *socks5BindConn) Handshake() (err error) {\n\tc.handshakeMux.Lock()\n\tdefer c.handshakeMux.Unlock()\n\n\tif c.handshaked {\n\t\treturn nil\n\t}\n\n\tc.handshaked = true\n\n\trep, err := gosocks5.ReadReply(c.Conn)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"bind: read reply %v\", err)\n\t}\n\tif rep.Rep != gosocks5.Succeeded {\n\t\treturn fmt.Errorf(\"bind: peer connect failure\")\n\t}\n\tc.raddr, err = net.ResolveTCPAddr(\"tcp\", rep.Addr.String())\n\treturn\n}\n\nfunc (c *socks5BindConn) Read(b []byte) (n int, err error) {\n\tif err = c.Handshake(); err != nil {\n\t\treturn\n\t}\n\treturn c.Conn.Read(b)\n}\n\nfunc (c *socks5BindConn) Write(b []byte) (n int, err error) {\n\tif err = c.Handshake(); err != nil {\n\t\treturn\n\t}\n\treturn c.Conn.Write(b)\n}","sourceCodeStart":1983,"sourceCodeEnd":2019,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/socks.go#L1983-L2019","documentation":"The SOCKS5 BIND handshake completed its first reply, but the second reply (sent when the peer connects) reports a non-Succeeded reply code (rep.Rep != gosocks5.Succeeded), meaning the remote peer's inbound connection to the server's bound port failed on the proxy side. This library turns any failed BIND reply code into this fixed error.","triggerScenarios":"Using a SOCKS5 BIND connection when the server's second reply carries a failure code — e.g. connection refused/blocked between the peer and the proxy's bound port, or the bind request was rejected at the second stage.","commonSituations":"Peer is behind a firewall and cannot reach the proxy's bind port; the proxy does not truly support BIND; NAT prevents the inbound connection; client is not reachable from the proxy network.","solutions":["Check the proxy server logs for the actual SOCKS5 reply code (e.g. connection refused, host unreachable)","Ensure the peer can reach the proxy's bound address/port (firewall/NAT rules)","Confirm the proxy server supports the BIND command at all — many modern proxies only support CONNECT","Prefer CONNECT-based dialing unless you specifically need reverse (BIND) connections"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// ensure the proxy supports BIND before relying on it\n// e.g. probe server capabilities or check server docs; no client-side API check exists\nif !proxySupportsBind(proxyAddr) { useConnectDialer() }","typeGuard":null,"tryCatchPattern":"c, err := bindDialer.Bind(ctx, addr)\nif err != nil {\n    if err.Error() == \"bind: peer connect failure\" {\n        c, err = connectDialer.Connect(ctx, addr) // fallback to CONNECT\n    }\n    if err != nil { return err }\n}","preventionTips":["Confirm the SOCKS5 server implements the BIND command","Ensure firewalls/NAT allow the peer to reach the proxy's bound port","Have a CONNECT-based fallback path","Check server reply codes in logs for root cause"],"tags":["socks5","bind","peer-connect","firewall"],"backgroundTag":"socks5-bind-refused","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}