Skip to content

Release v1.0.0-beta.2 - #133

Merged
Nemu-x merged 55 commits into
mainfrom
dev
Oct 18, 2026
Merged

Nemu-x merged 55 commits into
mainfrom
dev

Conversation

@Nemu-x

@Nemu-x Nemu-x commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

Второй бета-релиз Citrus: v1.0.0-beta.2.

Вливает в main всё, что накопилось в dev после беты 1 (#112–#132), кроме #130 (AnyTLS, доделывается к следующей бете):

Полный список — журнал изменений.

Известное: TUIC принимает не больше 2048 потоков на одно QUIC-соединение.

После мержа релиз собирается вручную: workflow Build, version = v1.0.0-beta.2 на main.

TokenPLS and others added 30 commits October 13, 2026 20:02
…s and dhcp

- anytls/padding: the scheme can be pushed by the server
  (cmdUpdatePaddingScheme). A negative "stop" wrapped to ~4e9 and a range
  like 1000000000-1000000001 made the client allocate a gigabyte for one
  padding record, while the length on the wire is a uint16. "stop" is now
  parsed as uint32 and sizes above 65535 are skipped.
- provider override expressions: integer literals and toNumber() parse with
  strconv.IntSize, so on 32-bit builds a value out of int range is an error
  (or a float for toNumber) instead of a silent truncation.
- github.com/klauspost/compress v1.17.9 -> v1.20.3 (GO-2026-5841) and
  github.com/insomniacslk/dhcp -> 20261014 (GO-2026-6237); neither
  vulnerable symbol was reachable, the bumps clear the module findings.
test.yml, pr-build.yml and bench.yml installed the MetaCubeX Go through
actions/setup-go with go-download-base-url, which takes whatever the
`build` release holds at the time. They now use setup-go.sh like the
release build, so every job runs a toolchain checked against a SHA-256.

The manifest gets a platform column and entries for linux-arm64,
darwin-amd64/arm64 and windows-amd64/arm64 (go1.26.9, hashes from the
downloaded assets, matching the release digests). setup-go.sh picks the
line for the runner's platform and works in Git Bash on Windows: zip
archives, mixed C:/ paths (MSYS_NO_PATHCONV-safe), Windows paths in
GITHUB_PATH and GOROOT; on macOS it falls back to shasum.

setup-go also cached GOCACHE and GOMODCACHE; test and PR build restore
them with actions/cache, keyed on go.sum and the manifest.
…led-upload test

Interop: runMihomoCase took the listener port and the controller port with
two freePort calls before starting anything. freePort closes its probe
sockets, so the OS could hand the same port out twice; in the failing run
the controller won the bind, the AnyTLS listener logged "address already in
use", waitPort on the controller passed, and the client's TLS handshake
reached the REST API ("first record does not look like a TLS handshake").
freePort now never returns a port twice in a run, and startCitrus fails the
case at once, with the log line, when a listener did not bind.

TrustTunnel: in TestFallbackRequestBodyStall the idle stage cancels the
backend request and the handler answers 502, but the watchdog's stuck stage
(abort writes) followed only one idle period (100 ms) later. On a loaded
Windows runner the 502 was not written in that window, so the write deadline
cut it off and the client read EOF. The stuck delay is now a separate
Service field, defaulting to the idle timeout (no change outside tests); the
test pushes it past the client's deadline, since that stage is covered by
TestFallbackClientStopsReading.
…nections

Crossing the quota (or expiring) closes the user's connections in a
goroutine. When that pass ran only after the quota was reset, raised, the
limit removed or the expiry moved, it closed the connections the user had
opened since, so the first reconnection after a reset could be dropped
(TestInboundUserLimitQuota flaked on it with unexpected EOF).

The closer now gets a still() check (over the quota / expire-at unchanged
and the limit not removed) and stops closing once it no longer holds.
fix: bound the AnyTLS padding scheme and number parsing; bump compress and dhcp
test: deflake the AnyTLS mihomo interop case and the TrustTunnel stalled-upload test
ci: pinned Go toolchain for tests, PR build and bench
fix(limits): a late close of a user over its quota spares its new connections
Upstream range bc76c13..94b13ae (3 commits):

94b13ae fix: dialer-proxy cycle check takes quadratic time and memory (MetaCubeX#3315)
df1b07a fix: a sub-millisecond URL test is reported as a failure (MetaCubeX#3316)
349af19 fix: the embedded shadowsocks listener can't be closed (MetaCubeX#3314)
Citrus accepted 5-13% fewer new connections per second than upstream
on the compare bench. The main cause is the GC: with ~3 MB live and no
globals, the heap goal was 6-8 MB against upstream's 17-20 MB, so
under a stream of short connections the collector ran three times as
often (gctrace: 1149 vs 340 cycles in the same run).

- gc_ballast.go: an 8 MiB pointer-free ballast, never written (no
  RSS, never scanned), raises the heap goal to upstream's level; left
  out when GOGC or GOMEMLIMIT is set.
- log: a line below the level is neither formatted nor sent to the
  log channel while nobody subscribes (/logs); log.Enabled lets
  callers skip building arguments; the sing logger and logMetadata
  use it.
- tracker: the count functions of UnwrapReader/UnwrapWriter, the ID
  string and TrackerInfo are allocated once with the tracker.
- trie: Search of an empty domain returns before building an error.
- Metadata: DstIPChecked moved next to DSCP, back to the 416-byte
  size class.
- tests: BenchmarkNewConn (tunnel, 144 -> 116 allocs/op); the UDP
  e2e tests close their sessions (the log channel no longer hid a
  test-order race on the resolver globals).
- compare bench: PPROF=1 also saves an allocs profile per window.
The ballast moves to component/gcballast, imported by main. It is left
out on android and ios (build tags) and in the embedded Android app
(features.CMFA), besides GOGC/GOMEMLIMIT: on a phone memory matters
more and new connections are few. Tests for the opt-outs.
perf: new connections — fewer GC cycles and allocations per connection
A TLS or Shadowsocks source returns one record or chunk per read, and the
relay wrote each with its own write(2): on a loaded server the 32-stream
Trojan upload spent 65% of its CPU in write(2). While the adaptive copy is
in a burst and the destination is a socket, a reader goroutine now keeps
decrypting up to 8 buffers ahead and the copy writes everything read
meanwhile with one writev(2). It never waits for data; when the burst ends
the source goes back to the copy loop, so idle connections still wait on
the small buffer without a goroutine.

Upload, 32 streams: Trojan 1792 -> 2683 MB/s, 1.06 -> 0.70 CPU s/GB;
SS2022 1801 -> 2814 MB/s, 1.07 -> 0.68; REALITY 1788 -> 2758 MB/s,
1.06 -> 0.69. Download, paced CPU per GB and xhttp unchanged.
perf(relay): batch upload writes with a read-ahead while a transfer runs
On Windows with core.autocrlf the bench scripts in test/bench/compare
(and the other *.sh / Dockerfile) were checked out with CRLF and broke
when run inside Linux containers.
Linux only, CGO_ENABLED=1. Covers transport/xhttp, transport/v2ray, transport/vless, common, tunnel, listener/sing and adapter. listener/inbound stays out until the smux fork fix lands; its ResTLS races are not ours to fix.
chore: LF for *.sh and Dockerfile; triage of -race in listener/inbound
A free UDP port can fall in a range Windows reserves for TCP, and the
TCP bind on it is then refused (WSAEACCES) on every retry.
ci: add a -race job for the race-clean packages
test(inbound): free TCP port for the SOCKS UDP user test
smux handed the caller's buffer to its send loop without copying and
could return from Stream.Write (session closed, socket error,
deadline) while the send loop still read it. The TLS layer then put the
buffer back into its pool and a dying session could send another
connection's data; -race on listener/inbound caught it as smux's send
loop racing with a TLS record buffer of another session.

The fork fixes it (getmikan/smux PR 2): a writer that gives up marks
its request abandoned under a per-request lock, so the send loop skips
it, and waits out a read already in progress.

Pinned to the merged dev commit as a pseudo-version until the fork has
a v*-citrus tag on main. test/bench/go.mod also picks up the dhcp and
klauspost/compress versions the root module already requires (go mod
tidy).
chore(deps): use the getmikan/smux fork
…AnyTLS

The harness compares Xray-core, sing-box, mihomo and Citrus as servers.

- fetch.sh pins sing-box v1.14.3 (musl build) and Xray v26.10.17, both
  checked against the release asset digests (Xray also its .dgst).
- cmp gen writes the sing-box configs and the new inbounds: Hysteria2,
  TUIC v5 and AnyTLS (sing-box, mihomo, Citrus; Xray has Hysteria2). A
  server without an inbound gets no config and run.sh skips it as n/a.
- One client per protocol for every server: Xray where it speaks the
  protocol, sing-box for TUIC and AnyTLS. QUIC runs skip the TCP checks.
- Xray's Hysteria server gets maxIncomingStreams 2^60, as the sing-quic
  servers have: with its default of 1024 its own client fails new streams.
- cmp report: four columns, n/a cells, headline.md with the winner per
  protocol (a tie when the min-max ranges overlap) and Citrus against the
  best other server; memory levels a server did not reach are left out;
  reality-tlsin uploads are marked not comparable (the client decides).
- run.sh: NAME, NET, SUBNET and IMAGE let setups share a host; ALONE=1
  waits for other containers before a run and flags the runs one starts
  during; ONLY reruns given runs; NET_ADMIN for the QUIC buffers. The
  client config path is per network, so its pkill does not hit the
  clients of another setup.
Nemu-x and others added 23 commits October 18, 2026 08:45
ReadAddress allocated addrLen+1 bytes with addrLen a byte: for the longest
domain the sum wrapped to 0 and the next index panicked, on the stream's
goroutine and before the connection had authenticated.
handleTCPConn started a goroutine per connection that waited up to 200 ms
for the client's first bytes, so that an outbound with a lazy handshake
could send them along; with three deadline changes on the inbound
connection and a 4 KiB read buffer. DIRECT and the rejecting outbounds never
have such a handshake: the proxy is now resolved first and the peek runs
only when the outbound (a group followed to the proxy it picks) may need
it.
Every inbound connection is wrapped in a BufferedConn, whose bufio.Reader
(4 KiB) was made at once. A connection that is only relayed reads through
ReadBuffer/ReadCached and never needs it. The reader is now made by the
first call that does; NewBufferedConnSize keeps an eager reader of a given
size, and TUIC uses it with 512 bytes for the CONNECT header of a stream.
Short proxied connections over one QUIC connection (the protocol alone and
through the core's tunnel to a TCP sink) and new QUIC connections.
Xray-core v26.10.17, sing-box v1.14.3, mihomo v1.19.32 and Citrus
cc48b13 (dev after the upload write batching, before the download
batching) as servers: REALITY (+ variants), XHTTP, Trojan, SS2022,
Hysteria2, TUIC and AnyTLS, 3 repetitions. RESULTS.md has the method,
the clients per protocol, the headline tables with the winner per
protocol, the verdict and the caveats; runs that another container
overlapped were redone and the originals kept under disturbed/.
perf(quic): less work per Hysteria2/TUIC stream; fix a TUIC CONNECT panic
test(bench): four-core server comparison (Xray, sing-box, mihomo, Citrus)
…y per stream

The TLS sink writes a ready byte after its handshake and acknowledges the
upload command, and cmp waits for both, so Xray's Vision client reads the
command record alone and switches every upload stream to direct copy
instead of at random. The Xray client of reality-tlsin logs at debug
level; cmp measure counts per bulk phase the streams whose upload and
download went direct, and cmp report ranks the reality-tlsin upload
metrics only when every upload stream of every run went direct.
…aseline

Short comparison (REALITY, Trojan, SS2022, Hysteria2; mem, hs, bulk) on
ubuntu-latest, nightly on dev, on demand and on pull requests touching
the harness. cmp gate compares the Citrus/mihomo ratio of each metric
with test/bench/compare/ci/baseline.json and fails on a drop of more than
the tolerance. run.sh: BUILD=host builds with the host's Go, SETTLE
shortens the memory phase.
With --pid=host, pkill -f reads the command line of every process of the
host and blocks on a process stuck in the kernel (D state), which hung
the runs of the comparison for minutes on a shared Docker host.
bench: deterministic reality-tlsin upload, nightly perf check in CI
An idle tunnel's handler goroutine spends its life blocked in the relay's
read, under every frame of the inbound and the tunnel that led there. The
runtime shrinks a goroutine stack at GC only when less than a quarter of it
is in use, and the setup (TLS handshake, dial) grows it to 16 KiB: with the
frames above the read at about 4.7 KiB (Trojan) the stack never came back to
8 KiB, and with the relay goroutine (4 KiB) an idle tunnel kept about 20 KiB
of stacks, the largest part of its memory.

The large frames above the relay move into functions of their own that
return before it starts: tunnel.handleTCPConn's setup (sniffing, rules,
limits, the dial: about 1 KiB) into dialTCPConn, the metadata of the sing
listener handler's NewConnection and HandleSocket, and the Trojan
authentication and request parsing. The Trojan chain above the read drops to
about 2.8 KiB, under the quarter of 16 KiB with the runtime's margin, and
Hysteria2's likewise, so the GC brings an idle tunnel's handler goroutine
back to 8 KiB.
An idle TLS connection now holds a 1 KiB raw input buffer instead of the
2-4 KiB its handshake grew (16-40 KiB after a full record), the frames above
its wait for the next record are smaller, and Conn.WaitRead lets the relay
wait without a buffer. Pinned to the branch of the fork's pull request until
it is released.
copyAdaptive waits for a source that looks idle on a small buffer (2 KiB),
taken before the read: an idle Trojan or VLESS/VMess-over-TLS tunnel held it
for as long as its client stayed silent. A source that can wait for data
without a buffer (getmikan/tls Conn.WaitRead) is now waited on first, and the
small buffer is taken once data is there. While a burst runs on full buffers
the copy reads as before.
A server session's goroutine waits for the next frame in recvLoop, under
Session.Run and the listener's HandleConn, for as long as the session lives.
recvLoop's frame (1.1 KiB, the handling of every command) and the
authentication in HandleConn kept the frames above that read over a quarter
of 16 KiB, so the runtime never shrank the goroutine back to 8 KiB. The
frame handling moves to handleFrame, the client part of Run to runClient
and the authentication to authenticate; the session goroutine of an idle
AnyTLS tunnel now shrinks to 8 KiB at GC.
…ps it

The relay unwraps a drained BufferedConn (ReaderReplaceable) before it asks
for cached data, so ReadCached, which dropped the bufio.Reader, was never
reached: a relayed conn that had been peeked (sniffing, an outbound with a
lazy handshake) kept its 4 KiB reader for its whole life. ReaderReplaceable
now drops a drained reader, and Read goes straight to the conn without one
instead of making it.
A relay loop of a bulk transfer on a loaded server never blocks, so the Go
scheduler lets it run for its whole 10 ms time slice, and the goroutine of an
interactive connection that the poller made runnable waits behind every such
loop: with 8 downloads on 2 cores, about 40 ms per hop through the server.

The copy loops (copyWait, copyAdaptive, both halves of copyBatched) now call
runtime.Gosched once they have moved 256 KiB and run for 1 ms since their
last yield. Both limits keep the yield rare: a Gosched also wakes an idle
processor, which costs a lone transfer on idle cores when it happens every
few hundred KiB, and a connection that moves little never yields.
perf(relay): bulk copy loops yield every millisecond: echo RTT under load 55-63 ms to 20 ms
perf: idle tunnels hold less (stacks, TLS raw input, relay buffer)
docs(changelog): #112-#131 and the forks for v1.0.0-beta.2
@Miroshka000
Miroshka000 requested review from Miroshka000 and removed request for Miroshka000 October 18, 2026 12:35
@Nemu-x
Nemu-x merged commit ecaa946 into main Oct 18, 2026
25 checks passed
Miroshka000 added a commit to Miroshka000/mikan that referenced this pull request Oct 18, 2026
The node is built with the head of the beta-2 release PR, its tls fork
moved with it.

This branch was previously deployed

1 inactive deployment
github-pages — be805459 Deployed Oct 18, 2026 by Nemu-x via deploy #35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants