{"record":{"id":"bbe7eea9e91aa413","repo":"shadow1ng/fscan","slug":"s-w-socks5-handshake-write-failed","errorCode":null,"errorMessage":"%s: %w [socks5_handshake_write_failed]","messagePattern":"(.+?): %w \\[socks5_handshake_write_failed\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/local/socks5proxy.go","lineNumber":183,"sourceCode":"\t\treturn fmt.Errorf(\"%s: %w\", i18n.GetText(\"socks5_handshake_read_failed\"), err)\n\t}\n\n\tif header[0] != 0x05 || header[1] == 0 {\n\t\treturn fmt.Errorf(\"%s\", i18n.GetText(\"socks5_unsupported_version\"))\n\t}\n\tmethods := make([]byte, int(header[1]))\n\tif _, err := io.ReadFull(conn, methods); err != nil {\n\t\treturn fmt.Errorf(\"%s: %w\", i18n.GetText(\"socks5_handshake_read_failed\"), err)\n\t}\n\tif !containsByte(methods, 0x00) {\n\t\t_, _ = conn.Write([]byte{0x05, 0xff})\n\t\treturn fmt.Errorf(\"%s\", i18n.GetText(\"socks5_unsupported_version\"))\n\t}\n\n\t// 发送握手响应（无认证）\n\tresponse := []byte{0x05, 0x00} // 版本5，无认证\n\tif _, err := conn.Write(response); err != nil {\n\t\treturn fmt.Errorf(\"%s: %w\", i18n.GetText(\"socks5_handshake_write_failed\"), err)\n\t}\n\n\treturn nil\n}\n\n// handleSocks5Request 处理SOCKS5连接请求\nfunc (p *Socks5ProxyPlugin) handleSocks5Request(clientConn net.Conn, session *common.ScanSession) (net.Conn, int, error) {\n\theader := make([]byte, 4)\n\tif _, err := io.ReadFull(clientConn, header); err != nil {\n\t\treturn nil, 0, fmt.Errorf(\"%s: %w\", i18n.GetText(\"socks5_request_read_failed\"), err)\n\t}\n\n\tif header[0] != 0x05 || header[2] != 0x00 {\n\t\treturn nil, 0, fmt.Errorf(\"%s\", i18n.GetText(\"socks5_invalid_request\"))\n\t}\n\n\tcmd := header[1]\n\tif cmd != 0x01 { // 只支持CONNECT命令","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/local/socks5proxy.go#L165-L201","documentation":"Wrap of a conn.Write failure at the end of the SOCKS5 handshake: the server selected no-auth (response bytes 0x05 0x00) but could not send the method-selection reply to the client (broken/peer-reset connection). The i18n socks5_handshake_write_failed prefix marks the handshake write stage and %w preserves the underlying network error.","triggerScenarios":"Thrown at plugins/local/socks5proxy.go:183 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Drop the client connection; the proxy loop will accept new ones","Check for network instability or a client-side timeout","Ensure no firewall is resetting long-lived proxy connections"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}