{"record":{"id":"5231cf3a8eeef8bf","repo":"shadow1ng/fscan","slug":"s-w-listen-port-failed","errorCode":null,"errorMessage":"%s: %w [listen_port_failed]","messagePattern":"(.+?): %w \\[listen_port_failed\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/local/socks5proxy.go","lineNumber":83,"sourceCode":"\t}\n\n\toutput.WriteString(i18n.GetText(\"socks5_done\") + \"\\n\")\n\tsession.LogSuccess(i18n.Tr(\"socks5_complete\", port))\n\n\treturn &plugins.Result{\n\t\tSuccess: true,\n\t\tType:    plugins.ResultTypeService,\n\t\tOutput:  output.String(),\n\t\tError:   nil,\n\t}\n}\n\n// startSocks5Server 启动SOCKS5代理服务器 - 核心实现\nfunc (p *Socks5ProxyPlugin) startSocks5Server(ctx context.Context, port int, state *common.State, session *common.ScanSession) error {\n\t// 监听指定端口\n\tlistener, err := net.Listen(\"tcp\", fmt.Sprintf(\"0.0.0.0:%d\", port))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s: %w\", i18n.GetText(\"listen_port_failed\"), err)\n\t}\n\tdefer func() { _ = listener.Close() }()\n\n\tp.listener = listener\n\tsession.LogSuccess(i18n.Tr(\"socks5_started\", port))\n\n\t// 设置SOCKS5代理为活跃状态，告诉主程序保持运行\n\tstate.SetSocks5ProxyActive(true)\n\tdefer func() {\n\t\t// 确保退出时清除活跃状态\n\t\tstate.SetSocks5ProxyActive(false)\n\t}()\n\n\t// 主循环处理连接\n\tfor {\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\tsession.LogInfo(i18n.GetText(\"socks5_cancelled\"))","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/local/socks5proxy.go#L65-L101","documentation":"Wrap of a net.Listen failure in startSocks5Server: the SOCKS5 proxy server could not bind/listen on 0.0.0.0:<port> (most commonly the port is already in use or privileges are insufficient). The i18n listen_port_failed prefix plus %w preserve the underlying network error; the deferred listener cleanup never runs because the listener was never created.","triggerScenarios":"net.Listen(\"tcp\", \"0.0.0.0:port\") returns err inside startSocks5Server — port already bound by another process, port is privileged (<1024) without rights, or binding to 0.0.0.0 is blocked.","commonSituations":"Another instance of the plugin/proxy still running on the same port; configured port collides with a local service; running in a container/sandbox without the port mapped or permitted.","solutions":["Check what holds the port (netstat -ano | findstr <port> / ss -ltnp) and stop it or choose a different port.","Configure the plugin with a high, unprivileged port (e.g. 1080, 18080).","On Linux, grant CAP_NET_BIND_SERVICE or use sysctl net.ipv4.ip_unprivileged_port_start if a low port is required.","Retry with port 0 to auto-assign a free ephemeral port if the port is not fixed by the tooling."],"exampleFix":"// before\nlistener, err := net.Listen(\"tcp\", fmt.Sprintf(\"0.0.0.0:%d\", port))\n// after — fail fast with a clear EADDRINUSE message\nlistener, err := net.Listen(\"tcp\", fmt.Sprintf(\"0.0.0.0:%d\", port))\nif err != nil {\n\tvar opErr *net.OpError\n\tif errors.As(err, &opErr) && errors.Is(opErr.Err, syscall.EADDRINUSE) {\n\t\treturn fmt.Errorf(\"port %d in use, pick another: %w\", port, err)\n\t}\n\treturn fmt.Errorf(\"%s: %w\", i18n.GetText(\"listen_port_failed\"), err)\n}","handlingStrategy":"retry","validationCode":"func portFree(port int) bool {\n\tl, err := net.Listen(\"tcp\", fmt.Sprintf(\"127.0.0.1:%d\", port))\n\tif err != nil {\n\t\treturn false\n\t}\n\t_ = l.Close()\n\treturn true\n}","typeGuard":"func isAddrInUse(err error) bool {\n\tvar opErr *net.OpError\n\treturn errors.As(err, &opErr) && errors.Is(opErr.Err, syscall.EADDRINUSE)\n}","tryCatchPattern":"listener, err := net.Listen(\"tcp\", addr)\nif err != nil {\n\tif isAddrInUse(err) {\n\t\t// pick another port or notify user\n\t}\n\treturn fmt.Errorf(\"%s: %w\", i18n.GetText(\"listen_port_failed\"), err)\n}","preventionTips":["Pick uncommon high ports (>=1024) for the proxy","Check port occupancy before starting the plugin","Ensure only one plugin instance runs per port","In containers, publish/bind the chosen port explicitly"],"tags":["network","tcp","socks5","listen"],"backgroundTag":"address-already-in-use","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}