mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6377] [MERGED] feat(clients): let admins set PersistentKeepalive on tunnel clients #6240
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6240
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6377
Author: @YoungReckless4
Created: 8/31/2026
Status: ✅ Merged
Merged: 9/10/2026
Merged by: @MHSanaei
Base:
main← Head:feat/amneziawg-client-keepalive📝 Commits (4)
b70e17efeat(clients): let admins set PersistentKeepalive on tunnel clients112b19afix(clients): let an explicit 0 actually disable PersistentKeepalivebe229a3Merge branch 'main' into feat/amneziawg-client-keepalive5675ba6fix(clients): repair the keepalive pointer conversion after the main merge📊 Changes
33 files changed (+220 additions, -34 deletions)
View changed files
📝
docs/public/openapi.json(+2 -0)📝
frontend/public/openapi.json(+2 -0)📝
frontend/src/generated/examples.ts(+1 -1)📝
frontend/src/generated/schemas.ts(+2 -0)📝
frontend/src/generated/types.ts(+1 -1)📝
frontend/src/generated/zod.ts(+1 -1)📝
frontend/src/pages/clients/ClientFormModal.tsx(+12 -0)📝
internal/database/model/model.go(+26 -5)📝
internal/database/model/model_wireguard_test.go(+21 -2)📝
internal/sub/clash_service.go(+4 -4)📝
internal/sub/clash_service_test.go(+2 -2)📝
internal/sub/json_service.go(+2 -2)📝
internal/sub/json_service_test.go(+1 -1)📝
internal/sub/service.go(+4 -4)📝
internal/sub/service_amneziawg_test.go(+1 -1)📝
internal/web/runtime/local.go(+2 -2)📝
internal/web/service/client_inbound_apply.go(+5 -5)➕
internal/web/service/client_update_keepalive_test.go(+102 -0)📝
internal/web/service/client_wireguard.go(+2 -2)📝
internal/web/service/xray_wireguard_config_test.go(+1 -1)...and 13 more files
📄 Description
The gap
model.Clientalready carriesKeepAlive(columnwg_keep_alive), the frontendschema already declares it (
schemas/protocols/inbound/amneziawg.ts), and everyclient-config emitter already writes
PersistentKeepalivewhen it is above zero —amneziaWGConfigTextin Go,buildAmneziaWGClientConfigandgenAmneziaWGConfigin TypeScript.
Nothing in the UI could set it. The client form has inputs for the private key,
public key, preshared key, allowed IPs and forwarded ports, but not this one, so the
value stayed at its 0 default and the line was never emitted for any client created
through the panel.
Why it matters
WireGuard only initiates a handshake when it has data to send. Without
PersistentKeepalivea peer that goes quiet has nothing to bring it back: it staysdisconnected after any interruption — a NAT mapping timing out, a device sleeping, the
panel restarting — until the user happens to generate traffic themselves. On a
UDP-obfuscated tunnel behind carrier NAT this is the common case, not the edge case.
The change
A
Keepalive (seconds)field in the client form, next to the other tunnel fields.New clients default to 25 — the conventional value, and short enough to sit inside the
~30s UDP NAT timeouts most carriers use. Existing clients keep whatever they have; the
form seeds from the stored value rather than overwriting it on save.
Translations added to all 13 locales — there is no English fallback, so a missing key
renders raw.
Making 0 actually mean 0
The hint text promises "0 disables it" and the backend refused it.
ClientService.Updatemarshals the client into the inbound settings JSON and
UpdateInboundClientunmarshalsit again, so
omitemptydropped an explicit 0 before the carry-forward — which treats azero
KeepAliveas "field not provided" and restores the stored value — ever saw it.The value could be raised, never lowered back to 0.
So
model.Client.KeepAliveis now a*int: nil means the field was never sent,&0means "send no keepalives".
ClientRecord.KeepAlivestays a plainint— it is thestored column, where "unset" has no meaning — and
KeepAliveSeconds()/KeepAlivePtr()bridge the two. A stored 0 converts back to nil, so the settings JSON keeps the shape it
has always had for the protocols that have no keepalive at all, rather than growing a
"keepAlive": 0on every client.API surface
keepAlivebecomesnumber | null(nullable: true) on the client schema, which is thesemantics the field now has. Worth naming for REST callers: an explicit
"keepAlive": 0used to mean "leave it alone" and now means "disable keepalives" — omitting the key keeps
the old behaviour. Regenerated with
make gen, andfrontend/public/openapi.jsoncopiedover
docs/public/openapi.json.Tests
TestUpdateCanClearKeepAliveOnAnExistingClient— 25 → an explicit 0 has to reachwg_keep_alive. Red without the fix:inbound keepAlive after an explicit 0 = 25.TestUpdateWithoutKeepAlivePreservesTheStoredValue— an update that omits the fieldleaves a stored 25 alone, which is what the carry-forward exists for.
TestClientToClientOmitsUnsetKeepAlive— a record that never set a keepalive must notemit
keepAliveinto the settings JSON, which reaches xray-core verbatim throughGenXrayInboundConfig.The existing
amneziawg-conf-parity.test.tscoversPersistentKeepalive's position inthe peer block and continues to pass.
make verifyis green.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.