{"record":{"id":"ba460125f4b9f437","repo":"XTLS/Xray-core","slug":"set-deadline-w-ba4601","errorCode":null,"errorMessage":"set deadline: %w","messagePattern":"set deadline: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"transport/internet/finalmask/xmc/server.go","lineNumber":55,"sourceCode":"\tprofiles        []loginProfile\n\tpassword        string\n\trsaPrivateKey   *rsa.PrivateKey\n\trsaPublicKey    []byte\n\tpaddingSchedule []paddingTurn\n\tpacket          *packetStream\n\tdeadlines       *connectionDeadlines\n}\n\nfunc (c *serverConn) handshake() error {\n\tc.handshakeLock.Lock()\n\tdefer c.handshakeLock.Unlock()\n\n\tif c.state != serverStateHandshake {\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\n\t\tserverAddress   String\n\t\tserverPort      UnsignedShort\n\t\tnextState       Varint\n\t)\n\n\t// handshake packet\n\n\tpkt, err := readPacket(c.reader)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"read handshake packet: %w\", err)\n\t}\n\n\tif pkt.packetID != 0 {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/transport/internet/finalmask/xmc/server.go#L37-L73","documentation":"serverConn.handshake fails when connectionDeadlines.beginHandshake cannot apply the 2-minute handshake read/write deadline to the underlying net.Conn (deadline.go:24-35 applies both deadlines via applyLocked). This means SetReadDeadline or SetWriteDeadline on the raw connection returned an error — typically because the connection is already closed or the wrapped conn type does not support deadlines.","triggerScenarios":"A client connects and the server begins the Minecraft handshake while the underlying net.Conn is closed (peer hung up immediately) or is a wrapped connection whose SetDeadline returns an error (e.g. a pipe, TLS conn after Close, or a custom net.Conn wrapper).","commonSituations":"Port scanners opening and instantly closing TCP connections to the proxy port; health checks that RST immediately; middleboxes or custom inbound wrappers in Xray that don't propagate deadlines; connections closed by a prior goroutine race.","solutions":["Check whether the peer disconnected immediately (scanner/health-check traffic) — usually harmless noise to log at debug level","Verify the net.Conn supplied to the server actually supports deadlines and is not already closed","Ensure no concurrent Close() races with handshake start in the connection accept loop","If wrapping conns in the inbound chain, forward SetReadDeadline/SetWriteDeadline correctly"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if tc, ok := conn.(*net.TCPConn); ok {\\n\\t_ = tc.SetDeadline(time.Now().Add(time.Minute)) // probe deadline support early\\n}","typeGuard":"func supportsDeadlines(c net.Conn) bool {\\n\\treturn c.SetReadDeadline(time.Now()) == nil && c.SetReadDeadline(time.Time{}) == nil\\n}","tryCatchPattern":"if err := conn.handshake(); err != nil && strings.Contains(err.Error(), \"set deadline\") {\\n\\t// conn is dead or deadline-unsupported: nothing to negotiate\\n\\tlog.Debug(\"xmc: connection unusable before handshake: \", err)\\n\\t_ = conn.Close()\\n}","preventionTips":["Ensure inbound wrappers forward SetReadDeadline/SetWriteDeadline to the underlying conn","Close connections only after handshake completes or from the same goroutine to avoid races","Expect scanner/health-check connections to fail here; log at debug level"],"tags":["go","network","deadline","handshake","xmc"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}