Skip to content

[Bug]: fragmentConn missing CloseWrite method when used with REALITY server (v26.7.11, regression from v26.6.1) #6509

Closed as not planned

Description

@skvarovski

Panic: fragmentConn missing CloseWrite method when used with REALITY server (v26.7.11, regression from v26.6.1)

Summary

Since v26.7.11, xray crashes (panic) on every client connection to a REALITY server inbound that uses finalmask with fragment + sudoku. The crash is caused by fragment.fragmentConn not implementing CloseWrite(), while a type assertion somewhere in the connection handling chain expects it.

This is a regression introduced by commit ad2e4cb0 (#6331), which reversed the TCP mask wrapping order via slices.Backward().

Panic

panic: interface conversion: *fragment.fragmentConn is not reality.CloseWriteConn: missing method CloseWrite

goroutine 8917 [running]:
created by github.com/xtls/xray-core/transport/internet/tcp.(*Listener).keepAccepting in goroutine 613

The panic is fatal (crashes the entire xray process). With Restart=always, this creates a crash-loop: every client connection with finalmask+Reality triggers the panic → crash → restart → next client → panic again.

Root Cause

Commit ad2e4cb0 ("Finalmask: Fix unexpected order and UDP's buf issue", #6331) changed the TCP mask wrapping order from forward to backward in transport/internet/finalmask/finalmask.go:

- for _, mask := range m.tcpmasks {                    // v26.6.1: forward
+ for _, mask := range slices.Backward(m.tcpmasks) {   // v26.7.11: backward

For a finalmask config {tcp: [{type:fragment}, {type:sudoku}]}:

Version Wrapping order Outermost wrapper Has CloseWrite()?
v26.6.1 (working) fragment(inner) → sudoku(outer) sudoku.wrappedConn ✅ yes (conn_tcp.go:139)
v26.7.11 (broken) sudoku(inner) → fragment(outer) fragment.fragmentConn ❌ no

sudoku/conn_tcp.go implements CloseWrite() error (delegates to underlying conn). fragment/conn.go does not.

When Reality (or XHTTP) server code type-asserts the connection to check for CloseWrite support, the assertion fails because fragmentConn is now the outermost wrapper and lacks the method.

Affected functions (all changed by the same commit):

  • WrapConnClient (line 216)
  • WrapConnServer (line 227) ← server-side, triggers the crash
  • WrapPacketConnClient (line 32)
  • WrapPacketConnServer (line 65)

Reproduction

  1. Set up a REALITY server inbound with finalmask containing both fragment and sudoku:
{
  "streamSettings": {
    "security": "reality",
    "finalmask": {
      "tcp": [
        {"type": "fragment", "settings": {"packets": "tlshello", "length": "100-300", "delay": "1-5"}},
        {"type": "sudoku", "settings": {"password": "...", "paddingMin": 10, "paddingMax": 50}}
      ]
    }
  }
}
  1. Start xray v26.7.11 (or v26.6.22+) with this config.
  2. Connect any client → xray crashes with the panic above.

Environment

  • Xray-core: v26.7.11 (also affects v26.6.22, v26.6.27, master)
  • Last working version: v26.6.1
  • OS: Linux (amd64, aarch64)
  • Protocol: VLESS + XHTTP + REALITY + finalmask (fragment + sudoku)
  • Role: Server (inbound) — client side is NOT affected

Suggested Fix

Option A (minimal): Add CloseWrite() to fragmentConn in transport/internet/finalmask/fragment/conn.go:

// CloseWrite implements the interface expected by REALITY/XHTTP server for half-close.
func (c *fragmentConn) CloseWrite() error {
    if cw, ok := c.Conn.(interface{ CloseWrite() error }); ok {
        return cw.CloseWrite()
    }
    return nil // underlying conn doesn't support CloseWrite
}

This mirrors what sudoku/conn_tcp.go already does (line 139-142).

Option B (alternative): Reconsider whether slices.Backward is the correct wrapping order for TCP masks. If the forward order was intentional (sudoku as outermost), the backward change may be wrong for the CloseWrite contract.

Impact

Any production server using REALITY + finalmask (fragment + sudoku) on v26.6.22+ will crash-loop. This is a common configuration for DPI bypass in restrictive network environments.

Workaround: Downgrade to v26.6.1, or remove fragment from finalmask TCP masks (sudoku-only doesn't trigger the panic since wrappedConn implements CloseWrite).

References

Activity

  1. changed the title [-]Panic: fragmentConn missing CloseWrite method when used with REALITY server (v26.7.11, regression from v26.6.1)[/-] [+][Bug]: fragmentConn missing CloseWrite method when used with REALITY server (v26.7.11, regression from v26.6.1)[/+] on Jul 16, 2026
  2. RPRX commented on Jul 16, 2026

    @RPRX
    Member

    @Fangliding 留着 panic 还是有点怪,加个配置检测吧,REALITY 暂时不能结合 Finalmask,文档也改一下

  3. Fangliding commented on Jul 16, 2026

    @Fangliding
    Member

    fragment+reality可能有一点点用? 要不还是之前那样兼容一下算了

  4. RPRX commented on Jul 16, 2026

    @RPRX
    Member

    都 fragment 了还管 SNI 是啥吗,只是为了 REALITY 那个回落?

  5. skvarovski commented on Jul 16, 2026

    @skvarovski
    Author
  6. Fangliding commented on Jul 16, 2026

    @Fangliding
    Member

    都 fragment 了还管 SNI 是啥吗,只是为了 REALITY 那个回落?

    这个issue看起来只是AI瞎扯的喜欢叠buff 不过在中国有一点点点用 比如省墙和国墙黑名单不一样 省墙黑名单一般更大但是有可能无法处理分片 带着分片能绕省墙然后过国墙啥的

    还有个办法是让finalmask的wrapper把closeread/write暴露出来给reality用

  7. Fangliding commented on Jul 16, 2026

    @Fangliding
    Member

    问题不大 不理也罢

  8. skvarovski commented on Jul 16, 2026

    @skvarovski
    Author

    Hello, I just tried to update xray on the relay server and got this error. After analyzing it, the AI ​​found this error (lack of closure).

  9. skvarovski commented on Jul 16, 2026

    @skvarovski
    Author

    @Fangliding 留着 panic 还是有点怪,加个配置检测吧,REALITY 暂时不能结合 Finalmask,文档也改一下

    If you suggest abandoning reality, then I can test it myself, but recently, using this particular stack has helped me achieve very stable operation, albeit with a decrease in speed.

    I thought that by updating the new version, my main goal was to test the Xray API to be able to update routing and add outbound on the fly.

  10. skvarovski commented on Jul 16, 2026

    @skvarovski
    Author

    Minimal verified fix for the panic: skvarovski@9de921ab
    fragmentConn lacks CloseWrite(). Once #6331 reverses the TCP mask order (slices.Backward)
    The fix adds CloseWrite() to fragmentConn (mirrors sudoku/conn_tcp.go) — additive, non-breaking, +11 lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions