XTLS/Xray-core · warning
set deadline: %w
Error message
set deadline: %w
What it means
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.
Source
Thrown at transport/internet/finalmask/xmc/server.go:55
profiles []loginProfile
password string
rsaPrivateKey *rsa.PrivateKey
rsaPublicKey []byte
paddingSchedule []paddingTurn
packet *packetStream
deadlines *connectionDeadlines
}
func (c *serverConn) handshake() error {
c.handshakeLock.Lock()
defer c.handshakeLock.Unlock()
if c.state != serverStateHandshake {
return nil
}
if err := c.deadlines.beginHandshake(); err != nil {
return fmt.Errorf("set deadline: %w", err)
}
defer func() { _ = c.deadlines.endHandshake() }()
var (
protocolVersion Varint
serverAddress String
serverPort UnsignedShort
nextState Varint
)
// handshake packet
pkt, err := readPacket(c.reader)
if err != nil {
return fmt.Errorf("read handshake packet: %w", err)
}
if pkt.packetID != 0 {View on GitHub (pinned to 7d214f8b09)
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
Defensive patterns
Strategy: try-catch
Validate before calling
if tc, ok := conn.(*net.TCPConn); ok {\n\t_ = tc.SetDeadline(time.Now().Add(time.Minute)) // probe deadline support early\n} Type guard
func supportsDeadlines(c net.Conn) bool {\n\treturn c.SetReadDeadline(time.Now()) == nil && c.SetReadDeadline(time.Time{}) == nil\n} Try / catch
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} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- set deadline: %w
- write handshake packet: %w
- write login start: %w
- read encryption request: %w
- bad encrypt request packet id
AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15).
Data as JSON: /api/errors/ba460125f4b9f437.
Report an issue: GitHub.