{"record":{"id":"de6e356659c6c509","repo":"XTLS/Xray-core","slug":"set-deadline-w","errorCode":null,"errorMessage":"set deadline: %w","messagePattern":"set deadline: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"transport/internet/finalmask/xmc/client.go","lineNumber":79,"sourceCode":"\t\tprofiles:        profiles,\n\t\tpassword:        password,\n\t\trsaPublicKey:    rsaPublicKey,\n\t\thostname:        hostname,\n\t\tpaddingSchedule: paddingSchedule,\n\t\tdeadlines:       newConnectionDeadlines(c),\n\t}, nil\n}\n\nfunc (c *clientConn) handshake() error {\n\tc.handshakeLock.Lock()\n\tdefer c.handshakeLock.Unlock()\n\n\tif c.state != clientStateHandshake {\n\t\treturn nil\n\t}\n\n\tif err := c.deadlines.beginHandshake(); err != nil {\n\t\treturn fmt.Errorf(\"set deadline: %w\", err)\n\t}\n\tdefer func() { _ = c.deadlines.endHandshake() }()\n\n\tvar (\n\t\tprotocolVersion Varint        = Varint(775)\n\t\tserverAddress   String        = String(c.hostname)\n\t\tserverPort      UnsignedShort = UnsignedShort(25565)\n\t\tnextState       Varint        = Varint(2)\n\t)\n\n\thost, portString, err := net.SplitHostPort(c.c.RemoteAddr().String())\n\tif err == nil {\n\t\tport, err := strconv.Atoi(portString)\n\t\tif err == nil {\n\t\t\tserverPort = UnsignedShort(port)\n\t\t}\n\n\t\tif serverAddress == \"\" {","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/transport/internet/finalmask/xmc/client.go#L61-L97","documentation":"Wraps a failure from deadlines.beginHandshake(), which sets the socket's read/write deadlines at the start of the Minecraft login handshake. The %w chains the underlying net.Conn.SetDeadline error, typically indicating the connection is already closed or the OS refused the deadline (e.g. invalid deadline on a wrapped conn).","triggerScenarios":"Calling handshake() on a conn that the peer already closed, or on a custom net.Conn wrapper whose SetDeadline returns an error. Timeout enforcement begins here, so dead conns surface at this point rather than at the first write.","commonSituations":"Server closed the TCP connection during a previous phase; aggressive server-side connection timeouts; passing a pipe or mock conn into the transport without deadline support.","solutions":["Check that the remote address/port is correct and the server accepts connections.","Unwrap the error (errors.As to *net.OpError) to see whether it is 'use of closed network connection' or a timeout.","If using a custom net.Conn wrapper, make sure SetDeadline is implemented rather than returning an error."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := cc.Handshake(); err != nil {\n\tvar opErr *net.OpError\n\tif errors.As(err, &opErr) && opErr.Op == \"set-deadline\" {\n\t\t// conn already dead or wrapper lacks deadline support\n\t\t_ = conn.Close()\n\t\treturn retryDial(ctx)\n\t}\n\treturn err\n}","preventionTips":["Ensure custom net.Conn wrappers implement SetDeadline instead of erroring.","Check conn state (peer closed, RST) before starting the handshake on reused sockets."],"tags":["network","xmc","finalmask","deadline","wrapped-error"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}