{"record":{"id":"d32853d98ec4b77d","repo":"fatedier/frp","slug":"connect-to-server-error-v","errorCode":null,"errorMessage":"connect to server error: %v","messagePattern":"connect to server error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/visitor/visitor.go","lineNumber":168,"sourceCode":"\t}\n}\n\nfunc (v *BaseVisitor) Close() {\n\tif v.l != nil {\n\t\tv.l.Close()\n\t}\n\tif v.internalLn != nil {\n\t\tv.internalLn.Close()\n\t}\n\tif v.plugin != nil {\n\t\tv.plugin.Close()\n\t}\n}\n\nfunc (v *BaseVisitor) dialRawVisitorConn(cfg *v1.VisitorBaseConfig) (net.Conn, error) {\n\tvisitorConn, err := v.helper.ConnectServer()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"connect to server error: %v\", err)\n\t}\n\n\tnow := time.Now().Unix()\n\ttargetProxyName := naming.BuildTargetServerProxyName(v.clientCfg.User, cfg.ServerUser, cfg.ServerName)\n\tnewVisitorConnMsg := &msg.NewVisitorConn{\n\t\tRunID:          v.helper.RunID(),\n\t\tProxyName:      targetProxyName,\n\t\tSignKey:        util.GetAuthKey(cfg.SecretKey, now),\n\t\tTimestamp:      now,\n\t\tUseEncryption:  cfg.Transport.UseEncryption,\n\t\tUseCompression: cfg.Transport.UseCompression,\n\t}\n\terr = visitorConn.WriteMsg(newVisitorConnMsg)\n\tif err != nil {\n\t\tvisitorConn.Close()\n\t\treturn nil, fmt.Errorf(\"send newVisitorConnMsg to server error: %v\", err)\n\t}\n","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/fatedier/frp/blob/6c8a8d0a97d03b44e9528d30b30c70cb9d61b405/client/visitor/visitor.go#L150-L186","documentation":"Thrown by BaseVisitor.dialRawVisitorConn when the visitor's helper.ConnectServer() — the control-connected TCP/TLS dial to frps — fails before it can send the NewVisitorConn message. The visitor cannot reach the frps server at all; the %v carries the dial error (timeout, refused, TLS, DNS).","triggerScenarios":"An stcp/sudp/xtcp visitor attempting a new visitor connection when the frps address is wrong/unreachable, the TLS settings mismatch, or the shared control connection's server has gone away; ConnectServer returns the transport-level error which is wrapped here.","commonSituations":"serverAddr/serverPort typo in the visitor's client config; frps restarted and visitor reconnect racing; transport.tls.enable differing between frpc and frps; NAT/firewall blocking the visitor's outbound connection to frps.","solutions":["Read the wrapped %v: 'connection refused' → wrong port or frps down; 'i/o timeout' → firewall/NAT; TLS errors → transport.tls mismatch.","Verify frps is running and reachable: nc -vz serverAddr serverPort from the visitor host.","Align transport.tls.enable and related TLS settings between frpc and frps.","If frps restarts frequently, ensure frpc's control connection re-login works (auth still valid) so visitors can redial."],"exampleFix":"# before\nserverAddr = \"192.168.1.50\"\nserverPort = 8000   # wrong port\n\n# after\nserverAddr = \"192.168.1.50\"\nserverPort = 7000","handlingStrategy":"retry","validationCode":"// Verify frps reachability before starting visitors\nconn, err := net.DialTimeout(\"tcp\", fmt.Sprintf(\"%s:%d\", serverAddr, serverPort), 3*time.Second)\nif err != nil { return fmt.Errorf(\"frps unreachable, visitor will fail: %w\", err) }\nconn.Close()","typeGuard":null,"tryCatchPattern":"// Visitors retry in their loops; in custom wrapping code classify the error\nif err := visitor.Run(); err != nil {\n    if strings.Contains(err.Error(), \"connect to server error\") {\n        log.Warnf(\"frps dial failed, retrying after backoff: %v\", err)\n        time.Sleep(backoff) // then retry visitor creation\n    }\n}","preventionTips":["Pin correct serverAddr/serverPort and keep them in shared config.","Match transport.tls settings between frpc and frps.","Monitor the frpc control connection; visitors depend on it for dialing."],"tags":["visitor","network","connection","frpc"],"backgroundTag":null,"analyzedSha":"6c8a8d0a97d03b44e9528d30b30c70cb9d61b405","analyzedAt":"2026-08-15T06:53:27.215Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}