[GH-ISSUE #5714] [Bug]: "Start after first use" does not activate the subscription expiration date #3978

Closed
opened 2026-10-31 20:36:17 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @DS-83 on GitHub (Jul 1, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5714

Describe the bug

When creating a new client with Start after first use enabled and a subscription duration (e.g. a number of days) configured, the subscription does not receive an expiration date after the client's first successful connection.

Instead, the client continues to display the "days" indicator as if the subscription has not started, and no expiration timestamp is assigned.

How to reproduce the problem

Start with a clean 3x-ui installation.
Create a new client.
Enable Start after first use.
Set a subscription duration (e.g. 30 days).
Save the client configuration.
Connect using the client for the first time.
Refresh the client information in the panel.

Expected behavior

After the first successful client connection, the subscription should start automatically and an expiration date should be calculated and assigned based on the configured duration.

Actual behavior

The subscription start is never triggered. No expiration date is assigned, and the client continues to display only the configured number of days as if the subscription has not yet started.

Relevant logs


Screenshots

Image

3x-ui version

3.4.2

Xray-core version

26.6.27

How did you install 3x-ui?

install.sh script

Operating system

CentOS 9

Which parts of the panel are affected?

Statistics / traffic counters

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @DS-83 on GitHub (Jul 1, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5714 ### Describe the bug When creating a new client with Start after first use enabled and a subscription duration (e.g. a number of days) configured, the subscription does not receive an expiration date after the client's first successful connection. Instead, the client continues to display the "days" indicator as if the subscription has not started, and no expiration timestamp is assigned. ### How to reproduce the problem Start with a clean 3x-ui installation. Create a new client. Enable Start after first use. Set a subscription duration (e.g. 30 days). Save the client configuration. Connect using the client for the first time. Refresh the client information in the panel. ### Expected behavior After the first successful client connection, the subscription should start automatically and an expiration date should be calculated and assigned based on the configured duration. ### Actual behavior The subscription start is never triggered. No expiration date is assigned, and the client continues to display only the configured number of days as if the subscription has not yet started. ### Relevant logs ```shell ``` ### Screenshots <img width="1547" height="73" alt="Image" src="https://github.com/user-attachments/assets/9e5aa031-a925-42ff-9fc0-c0ed5d23fa5d" /> ### 3x-ui version 3.4.2 ### Xray-core version 26.6.27 ### How did you install 3x-ui? install.sh script ### Operating system CentOS 9 ### Which parts of the panel are affected? Statistics / traffic counters ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:36:17 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Jul 1, 2026):

Thank you for the detailed report. I traced how "Start After First Use" is implemented and could not find an obvious break in the mechanism for a plain single-panel install, so I need a couple of specific details to pin this down rather than guess.

How the feature is implemented (confirmed in source)

  • When "Start After First Use" is enabled, the panel stores the duration as a negative expiryTime (e.g. -2592000000 ms for 30 days) - see frontend/src/pages/clients/ClientFormModal.tsx:464-466. The client is written to the Xray config immediately with enable: true; nothing blocks the connection until this value is activated.
  • The conversion to an absolute deadline happens in adjustTraffics (internal/web/service/inbound_traffic.go:183-284), which runs inside XrayTrafficJob every 5 seconds (cadenceXrayTraffic = "@every 5s", internal/web/web.go:289). It only fires for a client whose email shows up in that poll's traffic report from Xray's stats API.
  • Xray's stats API handling (internal/xray/api.go:655-668) treats the first time it ever sees a given per-user counter as a baseline (it is skipped, not reported as traffic) - so the conversion needs the client to have passed actual data through the proxy, and needs the following 5-second poll after that to see it, i.e. up to ~10 seconds after the first real traffic, not the mere act of connecting.
  • Once converted, the new deadline is written both into the inbound's client JSON and into the client_traffics.expiry_time column (internal/web/service/inbound_traffic.go:169-178), which is what the Clients page reads for the "days" column.

Two related bugs already fixed in 3.4.2

  • A multi-node bug where an un-activated node's report could clobber an already-activated deadline back to negative (fixed in #5319 / commit 6284061, merged 2026-06-15 - included in 3.4.1 and 3.4.2).
  • A bug where a stale client_traffics.inbound_id (after an inbound delete+recreate) made the lookup resolve no inbound and silently skip the conversion - also fixed, and covered by a regression test (TestAdjustTraffics_DelayedStartConvertsDespiteStaleInboundId).

Since your report does not mention multi-node and you are already on 3.4.2, this does not look like either of those. To narrow it down, please provide:

  1. Is this client attached only to a local inbound on this single panel, or is any node/remote panel involved at all?
  2. Which inbound protocol is the client on (VLESS/VMess/Trojan/Shadowsocks/WireGuard/etc.)?
  3. Did the client actually transfer data through the proxy (not just a bare connection attempt), and did you wait at least ~15 seconds after that before refreshing?
  4. If you have shell access to the server, the raw DB value would tell us whether this is a backend conversion failure or a UI display issue:
    sqlite3 /etc/x-ui/x-ui.db "SELECT email, expiry_time, up, down FROM client_traffics WHERE email='';"
    A negative expiry_time means the conversion never ran; a positive one that the UI still shows as "not started" would point to a frontend/display issue instead.
  5. If possible, panel logs from around the time of the first connection with XUI_LOG_LEVEL=debug set.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4854186348 --> @github-actions[bot] commented on GitHub (Jul 1, 2026): Thank you for the detailed report. I traced how "Start After First Use" is implemented and could not find an obvious break in the mechanism for a plain single-panel install, so I need a couple of specific details to pin this down rather than guess. **How the feature is implemented (confirmed in source)** - When "Start After First Use" is enabled, the panel stores the duration as a **negative** `expiryTime` (e.g. `-2592000000` ms for 30 days) - see `frontend/src/pages/clients/ClientFormModal.tsx:464-466`. The client is written to the Xray config immediately with `enable: true`; nothing blocks the connection until this value is activated. - The conversion to an absolute deadline happens in `adjustTraffics` (`internal/web/service/inbound_traffic.go:183-284`), which runs inside `XrayTrafficJob` every 5 seconds (`cadenceXrayTraffic = "@every 5s"`, `internal/web/web.go:289`). It only fires for a client whose email shows up in that poll's traffic report from Xray's stats API. - Xray's stats API handling (`internal/xray/api.go:655-668`) treats the first time it ever sees a given per-user counter as a baseline (it is skipped, not reported as traffic) - so the conversion needs the client to have passed actual data through the proxy, and needs the following 5-second poll after that to see it, i.e. up to ~10 seconds after the first real traffic, not the mere act of connecting. - Once converted, the new deadline is written both into the inbound's client JSON and into the `client_traffics.expiry_time` column (`internal/web/service/inbound_traffic.go:169-178`), which is what the Clients page reads for the "days" column. **Two related bugs already fixed in 3.4.2** - A multi-node bug where an un-activated node's report could clobber an already-activated deadline back to negative (fixed in #5319 / commit `6284061`, merged 2026-06-15 - included in 3.4.1 and 3.4.2). - A bug where a stale `client_traffics.inbound_id` (after an inbound delete+recreate) made the lookup resolve no inbound and silently skip the conversion - also fixed, and covered by a regression test (`TestAdjustTraffics_DelayedStartConvertsDespiteStaleInboundId`). Since your report does not mention multi-node and you are already on 3.4.2, this does not look like either of those. To narrow it down, please provide: 1. Is this client attached only to a local inbound on this single panel, or is any node/remote panel involved at all? 2. Which inbound protocol is the client on (VLESS/VMess/Trojan/Shadowsocks/WireGuard/etc.)? 3. Did the client actually transfer data through the proxy (not just a bare connection attempt), and did you wait at least ~15 seconds after that before refreshing? 4. If you have shell access to the server, the raw DB value would tell us whether this is a backend conversion failure or a UI display issue: sqlite3 /etc/x-ui/x-ui.db "SELECT email, expiry_time, up, down FROM client_traffics WHERE email='<client email>';" A negative expiry_time means the conversion never ran; a positive one that the UI still shows as "not started" would point to a frontend/display issue instead. 5. If possible, panel logs from around the time of the first connection with `XUI_LOG_LEVEL=debug` set. *This reply was generated automatically; a maintainer may follow up.*
Author
Owner

@DS-83 commented on GitHub (Jul 1, 2026):

  1. A node/remote panel is involved.

  2. Protocol: VLESS.

  3. Yes. The client successfully transferred traffic through the proxy (not just a connection attempt), and I waited well over 15 seconds before refreshing the panel.

  4. The database contains the correct expiration timestamp:
    1798448344010

    So it appears that the backend does update the value correctly. The issue is that the panel continues to display the client as "Start after first use" with the configured number of days instead of showing the actual expiration date.

  5. Unfortunately, I don't have debug logs available.

<!-- gh-comment-id:4855024669 --> @DS-83 commented on GitHub (Jul 1, 2026): 1. A node/remote panel is involved. 2. Protocol: **VLESS**. 3. Yes. The client successfully transferred traffic through the proxy (not just a connection attempt), and I waited well over 15 seconds before refreshing the panel. 4. The database contains the correct expiration timestamp: `1798448344010` So it appears that the backend does update the value correctly. The issue is that the panel continues to display the client as "Start after first use" with the configured number of days instead of showing the actual expiration date. 5. Unfortunately, I don't have debug logs available.
Author
Owner

@MHSanaei commented on GitHub (Jul 2, 2026):

Fixed in 8dd3b31e: at the end of every node sync the master now lifts an activated deadline from client_traffics onto client records that still hold the negative "start after first use" duration, so the Clients page shows the real expiry date instead of the un-started day counter. Your existing panel will self-heal on the first node sync after updating. Will ship in the next release.

<!-- gh-comment-id:4863442900 --> @MHSanaei commented on GitHub (Jul 2, 2026): Fixed in 8dd3b31e: at the end of every node sync the master now lifts an activated deadline from client_traffics onto client records that still hold the negative "start after first use" duration, so the Clients page shows the real expiry date instead of the un-started day counter. Your existing panel will self-heal on the first node sync after updating. Will ship in the next release.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3978
No description provided.