XTLS/Xray-core · error

new handshake needed

Error message

new handshake needed

What it means

Client-side recovery path in CommonConn.Read: a record header decoded with an 'invalid header:' error while a 0-RTT session was in use. Because the server may have expired the session and answered with a fresh handshake (or noise), the client invalidates its PFS key and signals the caller to perform a full new handshake instead of treating it as a fatal protocol error.

Solutions

  1. Catch this error and re-run the full handshake (new ClientInstance.Handshake), then resend the 0-RTT data
  2. Ensure server session expiry windows (secondsFrom/secondsTo) are wide enough for the client's usage pattern
  3. Keep session state in sync so expired tickets are not reused
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at proxy/vless/encryption/common.go:118 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/5cfa8761c321f68d. Report an issue: GitHub.

Appendix: source

Thrown at proxy/vless/encryption/common.go:118

		}
		c.PeerPadding = nil
	}
	if c.input.Len() > 0 {
		return c.input.Read(b)
	}
	peerHeader := [5]byte{}
	if _, err := io.ReadFull(c.Conn, peerHeader[:]); err != nil {
		return 0, err
	}
	l, err := DecodeHeader(peerHeader[:]) // l: 17~16640
	if err != nil {
		if c.Client != nil && strings.Contains(err.Error(), "invalid header: ") { // client's 0-RTT
			c.Client.RWLock.Lock()
			if bytes.HasPrefix(c.UnitedKey, c.Client.PfsKey) {
				c.Client.Expire = time.Now() // expired
			}
			c.Client.RWLock.Unlock()
			return 0, errors.New("new handshake needed")
		}
		return 0, err
	}
	c.Client = nil
	if c.rawInput.Cap() < l {
		c.rawInput.Grow(l) // no need to use sync.Pool, because we are always reading
	}
	peerData := c.rawInput.Bytes()[:l]
	if _, err := io.ReadFull(c.Conn, peerData); err != nil {
		return 0, err
	}
	dst := peerData[:l-16]
	if len(dst) <= len(b) {
		dst = b[:len(dst)] // avoids another copy()
	}
	var newAEAD *AEAD
	if bytes.Equal(c.PeerAEAD.Nonce[:], MaxNonce) {
		newAEAD = NewAEAD(append(peerHeader[:], peerData...), c.UnitedKey, c.UseAES)

View on GitHub (pinned to 7d214f8b09)