[PR #5496] [CLOSED] fix(job): handle access-log errors and resolve IP-limit clients relationally #5904

Closed
opened 2026-11-02 04:04:54 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5496
Author: @n0ctal
Created: 6/22/2026
Status: ❌ Closed

Base: main ← Head: pr-0016-iplimit-job-hardening


📝 Commits (2)

  • 69c10f9 fix(job): handle access-log errors and resolve IP-limit clients relationally
  • fe0197a Merge branch 'main' into pr-0016-iplimit-job-hardening

📊 Changes

2 files changed (+108 additions, -13 deletions)

View changed files

📝 internal/web/job/check_client_ip_job.go (+63 -13)
📝 internal/web/job/check_client_ip_job_integration_test.go (+45 -0)

📄 Description

Summary

The client IP-limit job ignored errors when opening/copying/truncating the Xray access log, and located a client's inbound with a fragile settings LIKE '%email%' substring query. This adds error handling with early returns, verifies the access log is actually readable, and resolves the client-to-inbound mapping via the clients/client_inbounds relation, keeping the substring scan only as a fallback.

Why

  • Swallowed errors (j.checkError(err) with no return) let the job keep running after a failed log open/copy/truncate, operating on inconsistent state.
  • WHERE settings LIKE '%email%' can match the wrong inbound: an email that is a substring of another email, or text that merely appears elsewhere in the settings JSON. The relational lookup is exact; the JSON scan remains as a fallback so nothing regresses when the relation has no row.

Scope

  • internal/web/job/check_client_ip_job.go:
    • clearAccessLog, processLogFile: check each file error and return early instead of continuing.
    • checkAccessLogAvailable: actually open the log to confirm readability (not just stat).
    • getInboundByEmail: join client_inbounds/clients on clients.email; on miss fall back to the previous LIKE + JSON parse.
  • internal/web/job/check_client_ip_job_integration_test.go: integration coverage.

Validation

go vet ./internal/web/job/, go build ./..., and the full internal/web/job package under -race all pass.

Risk

getInboundByEmail now prefers the relational tables and falls back to the prior substring+JSON scan, so the result is unchanged when the join finds nothing. No schema change; no behavioral change for the common single-match case.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5496 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 6/22/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr-0016-iplimit-job-hardening` --- ### 📝 Commits (2) - [`69c10f9`](https://github.com/MHSanaei/3x-ui/commit/69c10f980386736c3786f8e434ad76307117f90b) fix(job): handle access-log errors and resolve IP-limit clients relationally - [`fe0197a`](https://github.com/MHSanaei/3x-ui/commit/fe0197a4bc7b109599a31c87a5316e4b7998538e) Merge branch 'main' into pr-0016-iplimit-job-hardening ### 📊 Changes **2 files changed** (+108 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/job/check_client_ip_job.go` (+63 -13) 📝 `internal/web/job/check_client_ip_job_integration_test.go` (+45 -0) </details> ### 📄 Description ## Summary The client IP-limit job ignored errors when opening/copying/truncating the Xray access log, and located a client's inbound with a fragile `settings LIKE '%email%'` substring query. This adds error handling with early returns, verifies the access log is actually readable, and resolves the client-to-inbound mapping via the `clients`/`client_inbounds` relation, keeping the substring scan only as a fallback. ## Why - Swallowed errors (`j.checkError(err)` with no return) let the job keep running after a failed log open/copy/truncate, operating on inconsistent state. - `WHERE settings LIKE '%email%'` can match the wrong inbound: an email that is a substring of another email, or text that merely appears elsewhere in the settings JSON. The relational lookup is exact; the JSON scan remains as a fallback so nothing regresses when the relation has no row. ## Scope - `internal/web/job/check_client_ip_job.go`: - `clearAccessLog`, `processLogFile`: check each file error and return early instead of continuing. - `checkAccessLogAvailable`: actually open the log to confirm readability (not just stat). - `getInboundByEmail`: join `client_inbounds`/`clients` on `clients.email`; on miss fall back to the previous `LIKE` + JSON parse. - `internal/web/job/check_client_ip_job_integration_test.go`: integration coverage. ## Validation `go vet ./internal/web/job/`, `go build ./...`, and the full `internal/web/job` package under `-race` all pass. ## Risk `getInboundByEmail` now prefers the relational tables and falls back to the prior substring+JSON scan, so the result is unchanged when the join finds nothing. No schema change; no behavioral change for the common single-match case. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:54 +07:00
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#5904
No description provided.