[GH-ISSUE #6023] [Bug/Improvement]: PostgreSQL outage causes misleading startup error, unlimited restart loop, and massive log growth #4171

Closed
opened 2026-10-31 20:37:43 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @z2roozsh on GitHub (Jul 18, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6023

Describe the bug

Summary

When 3X-UI is configured to use PostgreSQL and the database becomes temporarily unavailable, the panel exits immediately. The systemd service then restarts it every five seconds without an effective restart limit.

The x-ui management script reports only:

[ERR] panel Failed to start, Probably because it takes longer than two seconds to start, Please check the log information later

In my case, the problem was not that startup required more than two seconds. The process exited almost immediately because PostgreSQL had crashed after the server filesystem became full.

Because the actual database error was not shown by the script, troubleshooting became unnecessarily difficult. At the same time, the automatic restart loop generated a very large number of log entries and made the disk-space problem worse.

I am reporting the full incident and recovery process so the installer, management script, systemd unit, and possibly the application itself can handle this failure mode more safely.


Environment

  • 3X-UI version: 3.5.0
  • Xray-core version after recovery: 26.7.11
  • Operating system: Ubuntu 24.04
  • PostgreSQL version: 16.14
  • Database backend: PostgreSQL
  • PostgreSQL address: 127.0.0.1:5433
  • PostgreSQL database: xui
  • Installation type: native systemd installation
  • Service file: /etc/systemd/system/x-ui.service
  • Environment file: /etc/default/x-ui
  • Root filesystem size: approximately 19 GB

Sensitive database credentials, public IP addresses, usernames, and hostnames have been removed from this report.


Initial user-visible behavior

The management menu showed:

Panel state: Not Running
Start automatically: Yes
xray state: Not Running

Selecting Start produced:

[ERR] panel Failed to start, Probably because it takes longer than two seconds to start, Please check the log information later

Restarting produced:

[ERR] Panel restart failed, Probably because it takes longer than two seconds to start, Please check the log information later

This message suggested a startup timing problem, but the service was actually exiting with status 1 almost immediately.


Actual service failure

systemctl status x-ui showed:

Active: activating (auto-restart) (Result: exit-code)
Process: ... ExecStart=/usr/local/x-ui/x-ui (code=exited, status=1/FAILURE)
Main PID: ... (code=exited, status=1/FAILURE)

The real error appeared only after manually running:

journalctl -u x-ui -n 100 --no-pager

The relevant message was:

Starting x-ui 3.5.0

Error initializing database:
failed to connect to `user=[REDACTED] database=xui`:
127.0.0.1:5433:
FATAL: the database system is in recovery mode
(SQLSTATE 57P03)

At other times during the incident, the database error was:

FATAL: the database system is shutting down
(SQLSTATE 57P03)

The panel could not initialize its database and exited. Xray therefore did not start under the x-ui service.


Root cause

The root filesystem had reached 100% usage:

Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        19G   19G     0 100% /

PostgreSQL attempted a checkpoint and failed:

PANIC: could not write to file
"pg_logical/replorigin_checkpoint.tmp":
No space left on device

PostgreSQL then terminated its server processes and entered automatic crash recovery:

checkpointer process was terminated by signal 6: Aborted
terminating any other active server processes
database system was not properly shut down
automatic recovery in progress

While PostgreSQL was unavailable, x-ui continued restarting every five seconds because the service contained:

Restart=on-failure
RestartSec=5s

There was no practical restart burst limit in the service configuration.

The restart counter reached at least:

restart counter is at 130

Log amplification

The full filesystem had multiple contributors, including SSH brute-force records and another verbose service. However, x-ui’s failure loop significantly amplified the incident.

The largest logs included:

772M /var/log/kern.log
275M /var/log/syslog
269M /var/log/btmp
244M /var/log/auth.log

When I counted program names in kern.log, I found:

4023499 /usr/local/x-ui/x-ui
3795    kernel

In other words, more than four million entries in kern.log were attributed to the x-ui executable.

The default rsyslog configuration was normal:

*.*;auth,authpriv.none    -/var/log/syslog
kern.*                    -/var/log/kern.log

This means x-ui’s userspace messages appear to have been submitted with a kernel syslog facility, or otherwise classified as kern.*.

Example entries found in kern.log:

/usr/local/x-ui/x-ui[PID]: INFO - GC percent set to 75
/usr/local/x-ui/x-ui[PID]: INFO - Go memory soft limit not enforced

A userspace panel process should not normally generate millions of entries in the kernel log.


PostgreSQL status was also misleading

On Debian/Ubuntu, this command showed:

systemctl status postgresql
postgresql.service - PostgreSQL RDBMS
Active: active (exited)

That wrapper unit looked healthy even though the actual PostgreSQL cluster was stuck.

The relevant unit was:

systemctl status postgresql@16-main

It showed:

Active: deactivating (stop-sigterm) (Result: exit-code)

The PostgreSQL process list contained a stuck cluster process and checkpointer.

Therefore, checking only postgresql.service is insufficient on Debian-based systems. Diagnostics should identify the actual cluster unit, for example through pg_lsclusters.


Recovery steps used

1. Stop the x-ui restart loop

I temporarily masked the service:

systemctl mask --runtime --now x-ui

This stopped further restart attempts without permanently disabling autostart.

2. Free disk space

I identified the largest logs and cleared the accumulated files after preserving diagnostic samples.

After cleanup:

Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        19G   12G  6.3G  66% /

3. Stop the stuck PostgreSQL cluster

A normal stop did not complete:

pg_ctl: server does not shut down

The cluster remained in deactivating state for more than 15 minutes.

An immediate PostgreSQL shutdown signal was then sent through systemd:

systemctl kill \
  --kill-whom=all \
  --signal=SIGQUIT \
  postgresql@16-main

This is an emergency recovery action, not something that should normally be required.

PostgreSQL then performed automatic crash recovery:

database system was not properly shut down
automatic recovery in progress
redo starts at ...
redo done at ...
checkpoint complete: end-of-recovery
database system is ready to accept connections

4. Verify PostgreSQL

pg_isready -h 127.0.0.1 -p 5433

Result:

127.0.0.1:5433 - accepting connections

Recovery status:

sudo -u postgres psql -p 5433 -Atc \
  'SELECT pg_is_in_recovery();'

Result:

f

5. Start x-ui again

systemctl unmask x-ui
systemctl reset-failed x-ui
systemctl start x-ui

The service then started successfully:

Active: active (running)

Web server running HTTPS on 0.0.0.0:2087
Sub server running HTTPS on 0.0.0.0:2096
Xray 26.7.11 started

The management menu finally showed:

Panel state: Running
Start automatically: Yes
xray state: Running

No database restoration was required, and no database corruption was detected after recovery.


Problems in the current behavior

1. The two-second check produces a misleading diagnosis

The current start/restart flow effectively performs:

systemctl start x-ui
sleep 2
check_status

If the process is not running, it says that startup probably took longer than two seconds.

This does not distinguish between:

  • service still activating;
  • process exited with status 1;
  • PostgreSQL unavailable;
  • invalid database credentials;
  • database in recovery;
  • database shutting down;
  • port conflict;
  • invalid configuration;
  • missing certificate;
  • filesystem full;
  • binary crash.

In this incident, the process had already exited. Waiting longer would never have fixed it.

2. The real error is hidden

The management script tells the user to check logs later but does not print the relevant logs or provide the exact command.

Many users will not know to run:

systemctl status x-ui --no-pager -l
journalctl -u x-ui -n 50 --no-pager

The script already has enough context to display these automatically.

3. Unlimited automatic retries create a log storm

A five-second restart interval without an effective burst limit means approximately:

12 restart attempts per minute
720 restart attempts per hour
17,280 restart attempts per day

A persistent dependency failure can therefore create enormous logs and unnecessary CPU/process churn.

4. PostgreSQL dependency health is not checked

If the configured backend is PostgreSQL, the management script does not appear to check whether the configured PostgreSQL endpoint is reachable before starting the panel.

It also does not recognize common PostgreSQL states such as:

SQLSTATE 57P03
database system is starting up
database system is in recovery mode
database system is shutting down

5. The database wrapper service can give a false healthy result

On Ubuntu, postgresql.service is a wrapper and may report active (exited) while the real cluster is unhealthy.

The script should inspect:

pg_lsclusters
systemctl status postgresql@VERSION-CLUSTER
pg_isready

when using a local PostgreSQL installation.

6. x-ui messages were written into kern.log

More than four million x-ui messages were present in /var/log/kern.log.

The application’s syslog facility should be reviewed. Userspace application logs should use an appropriate facility such as:

  • daemon;
  • user;
  • local0;
  • or normal stderr/stdout captured by journald.

They should not be classified as kernel messages.

7. Global Xray process detection may be inaccurate

The script appears to determine Xray status by globally searching for an xray-linux process.

On servers where another panel or service also runs Xray, this can report:

xray state: Running

even if the Xray instance belonging to 3X-UI is not running.

Xray status should be scoped to:

  • the x-ui systemd cgroup;
  • the child PID started by x-ui;
  • a PID file;
  • or the specific configured executable and parent PID.

Suggested improvements

A. Replace the fixed two-second sleep with a bounded service-state loop

Example logic:

wait_for_xui() {
    local timeout="${1:-30}"
    local elapsed=0

    while (( elapsed < timeout )); do
        if systemctl is-active --quiet x-ui; then
            return 0
        fi

        if systemctl is-failed --quiet x-ui; then
            return 1
        fi

        sleep 1
        ((elapsed++))
    done

    return 2
}

The result could distinguish:

  • 0: started successfully;
  • 1: exited or failed;
  • 2: still activating after timeout.

B. Print immediate diagnostics on failure

When start or restart fails, automatically show:

systemctl status x-ui --no-pager -l
journalctl -u x-ui -n 30 --no-pager

The output should preferably be filtered to the current boot or current invocation:

journalctl -u x-ui -b -n 30 --no-pager

The script should print the actual ExecMainStatus and service result:

systemctl show x-ui \
  -p ActiveState \
  -p SubState \
  -p Result \
  -p ExecMainCode \
  -p ExecMainStatus

Example user-facing output:

Panel failed to start.

Service result: exit-code
Exit status: 1

Last error:
Error initializing database:
FATAL: the database system is in recovery mode

Suggested action:
Check PostgreSQL availability and available disk space.

C. Add PostgreSQL preflight diagnostics

When XUI_DB_TYPE=postgres, the script should read the configured DSN from the environment file and test the database host and port without printing the password.

Possible checks:

pg_isready -h "$db_host" -p "$db_port" -d "$db_name"

If pg_isready is unavailable, a TCP connectivity test could be used as a fallback.

The script should not log the full DSN because it contains credentials.

Recognized error states should include:

SQLSTATE 57P03
database system is starting up
database system is in recovery mode
database system is shutting down
connection refused
password authentication failed
no pg_hba.conf entry

D. Detect disk exhaustion automatically

When PostgreSQL or x-ui fails, the diagnostic routine should run:

df -P /
df -i /

If any relevant filesystem is near capacity, show a prominent warning:

Critical: filesystem / is 100% full.

PostgreSQL cannot complete checkpoints or crash recovery without
free disk space. Free space before restarting x-ui repeatedly.

It could also search recent PostgreSQL logs for:

No space left on device
could not write to file
PANIC
checkpoint

E. Inspect the real PostgreSQL cluster on Debian/Ubuntu

For a locally installed PostgreSQL server:

pg_lsclusters --no-header

Then inspect the actual cluster service:

systemctl status "postgresql@${version}-${cluster}"

Do not rely only on:

systemctl status postgresql

because that unit may be active (exited) while a cluster is unavailable.

F. Stop automatic retries when a persistent dependency failure is detected

The script could stop the service after detecting a PostgreSQL failure:

systemctl stop x-ui
systemctl reset-failed x-ui

It should tell the user that x-ui was stopped to prevent a restart/log loop.

A temporary runtime mask could optionally be offered:

systemctl mask --runtime x-ui

This should not be applied silently, but it could be presented as an interactive recovery option.

G. Add systemd restart limits

A safer service configuration would include something similar to:

[Unit]
StartLimitIntervalSec=300
StartLimitBurst=5

[Service]
Restart=on-failure
RestartSec=30s

This allows recovery from temporary failures but prevents indefinite five-second loops.

Another option is exponential or progressively increasing restart backoff if supported by the target systemd versions.

H. Add application-level database retry/backoff

Instead of exiting immediately after one failed connection, the backend could retry PostgreSQL initialization with bounded exponential backoff.

Example behavior:

Database unavailable: PostgreSQL is in recovery.
Retrying in 5 seconds...
Retrying in 10 seconds...
Retrying in 20 seconds...

After a reasonable timeout, it could exit with one clear final error.

This would avoid hundreds of complete process restarts for a short PostgreSQL recovery.

I. Correct the logging facility

Please audit how x-ui submits logs to syslog/journald.

Messages such as:

INFO - GC percent set to 75
INFO - Go memory soft limit not enforced

should not be written with the kern facility.

Recommended behavior:

  • write structured logs to stdout/stderr under systemd;
  • or use a userspace syslog facility;
  • rely on journald and log rotation;
  • avoid duplicating the same output into multiple large files.

J. Add an x-ui doctor command

A diagnostic command could test:

- x-ui binary and permissions
- systemd service state and exit status
- configured database backend
- PostgreSQL connectivity
- local PostgreSQL cluster state
- filesystem and inode usage
- panel and subscription ports
- certificate file existence and permissions
- Xray configuration validation
- Xray process ownership
- last relevant logs

Example:

x-ui doctor

Possible output:

[OK] x-ui binary found
[FAIL] PostgreSQL 127.0.0.1:5433 is not ready
[FAIL] Root filesystem is 100% full
[WARN] x-ui has restarted 126 times
[WARN] 772 MB kern.log contains repeated x-ui entries

Primary diagnosis:
PostgreSQL crashed because the filesystem is full.
x-ui has been stopped to prevent further restart attempts.

K. Scope Xray status to the x-ui service

Instead of a global process search, use a service-scoped check such as:

systemctl show x-ui -p MainPID
systemctl status x-ui
systemd-cgls /system.slice/x-ui.service

Or track the exact Xray child process started by the panel.

This avoids reporting another application’s Xray process as the 3X-UI Xray process.


Expected behavior

When the panel fails because PostgreSQL is unavailable, the management script should provide an actionable message such as:

3X-UI could not start because its PostgreSQL database is unavailable.

Database:
  Host: 127.0.0.1
  Port: 5433
  Name: xui

PostgreSQL response:
  FATAL: the database system is in recovery mode
  SQLSTATE: 57P03

Filesystem:
  / is 100% full

The x-ui service has been stopped to prevent an automatic restart loop.

Recommended steps:
  1. Free disk space.
  2. Verify the PostgreSQL cluster.
  3. Run: x-ui start

It should not describe this situation as probably taking longer than two seconds.


Proposed acceptance criteria

  1. A failed process exit is distinguished from a slow startup.
  2. Start/restart failures show the actual systemd result and recent logs.
  3. PostgreSQL configurations receive a database connectivity preflight.
  4. SQLSTATE 57P03 produces a database-specific explanation.
  5. Disk and inode usage are checked after database-related failures.
  6. The default service cannot restart forever every five seconds.
  7. x-ui userspace logs no longer enter kern.log.
  8. Xray status is scoped to the x-ui-managed process.
  9. Debian/Ubuntu diagnostics inspect the real PostgreSQL cluster unit.
  10. A diagnostic or doctor command can summarize the likely root cause.

Final result after manual recovery

After freeing disk space, recovering PostgreSQL, and restarting x-ui:

PostgreSQL: accepting connections
pg_is_in_recovery(): false
Panel state: Running
Start automatically: Yes
xray state: Running

The panel, subscription server, and Xray core all started successfully.

This incident was ultimately recoverable, but the management script’s generic message and the unbounded restart loop made the failure much harder to diagnose and significantly increased log volume. Better dependency diagnostics and restart controls would make this class of incident much safer for other users.

How to reproduce the problem

Actual service failure

systemctl status x-ui showed:

Active: activating (auto-restart) (Result: exit-code)
Process: ... ExecStart=/usr/local/x-ui/x-ui (code=exited, status=1/FAILURE)
Main PID: ... (code=exited, status=1/FAILURE)

The real error appeared only after manually running:

journalctl -u x-ui -n 100 --no-pager

The relevant message was:

Starting x-ui 3.5.0

Error initializing database:
failed to connect to user=[REDACTED] database=xui:
127.0.0.1:5433:
FATAL: the database system is in recovery mode
(SQLSTATE 57P03)

At other times during the incident, the database error was:

FATAL: the database system is shutting down
(SQLSTATE 57P03)

The panel could not initialize its database and exited. Xray therefore did not start under the x-ui service.

Root cause

The root filesystem had reached 100% usage:

Filesystem Size Used Avail Use% Mounted on
/dev/vda1 19G 19G 0 100% /

PostgreSQL attempted a checkpoint and failed:

PANIC: could not write to file
"pg_logical/replorigin_checkpoint.tmp":
No space left on device

PostgreSQL then terminated its server processes and entered automatic crash recovery:

checkpointer process was terminated by signal 6: Aborted
terminating any other active server processes
database system was not properly shut down
automatic recovery in progress

While PostgreSQL was unavailable, x-ui continued restarting every five seconds because the service contained:

Restart=on-failure
RestartSec=5s

There was no practical restart burst limit in the service configuration.

The restart counter reached at least:

restart counter is at 130
Log amplification

The full filesystem had multiple contributors, including SSH brute-force records and another verbose service. However, x-ui’s failure loop significantly amplified the incident.

The largest logs included:

772M /var/log/kern.log
275M /var/log/syslog
269M /var/log/btmp
244M /var/log/auth.log

When I counted program names in kern.log, I found:

4023499 /usr/local/x-ui/x-ui
3795 kernel

In other words, more than four million entries in kern.log were attributed to the x-ui executable.

The default rsyslog configuration was normal:

.;auth,authpriv.none -/var/log/syslog
kern.* -/var/log/kern.log

This means x-ui’s userspace messages appear to have been submitted with a kernel syslog facility, or otherwise classified as kern.*.

Example entries found in kern.log:

/usr/local/x-ui/x-ui[PID]: INFO - GC percent set to 75
/usr/local/x-ui/x-ui[PID]: INFO - Go memory soft limit not enforced

A userspace panel process should not normally generate millions of entries in the kernel log.

PostgreSQL status was also misleading

On Debian/Ubuntu, this command showed:

systemctl status postgresql
postgresql.service - PostgreSQL RDBMS
Active: active (exited)

That wrapper unit looked healthy even though the actual PostgreSQL cluster was stuck.

The relevant unit was:

systemctl status postgresql@16-main

It showed:

Active: deactivating (stop-sigterm) (Result: exit-code)

The PostgreSQL process list contained a stuck cluster process and checkpointer.

Therefore, checking only postgresql.service is insufficient on Debian-based systems. Diagnostics should identify the actual cluster unit, for example through pg_lsclusters.

Expected behavior

No response

Actual behavior

Initial user-visible behavior

The management menu showed:

Panel state: Not Running
Start automatically: Yes
xray state: Not Running

Selecting Start produced:

[ERR] panel Failed to start, Probably because it takes longer than two seconds to start, Please check the log information later

Restarting produced:

[ERR] Panel restart failed, Probably because it takes longer than two seconds to start, Please check the log information later

This message suggested a startup timing problem, but the service was actually exiting with status 1 almost immediately.

Relevant logs


Screenshots

No response

3x-ui version

3.5.0

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

linux ubuntu 22

Which parts of the panel are affected?

No response

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 @z2roozsh on GitHub (Jul 18, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6023 ### Describe the bug ## Summary When 3X-UI is configured to use PostgreSQL and the database becomes temporarily unavailable, the panel exits immediately. The systemd service then restarts it every five seconds without an effective restart limit. The `x-ui` management script reports only: ```text [ERR] panel Failed to start, Probably because it takes longer than two seconds to start, Please check the log information later ``` In my case, the problem was not that startup required more than two seconds. The process exited almost immediately because PostgreSQL had crashed after the server filesystem became full. Because the actual database error was not shown by the script, troubleshooting became unnecessarily difficult. At the same time, the automatic restart loop generated a very large number of log entries and made the disk-space problem worse. I am reporting the full incident and recovery process so the installer, management script, systemd unit, and possibly the application itself can handle this failure mode more safely. --- ## Environment * 3X-UI version: `3.5.0` * Xray-core version after recovery: `26.7.11` * Operating system: Ubuntu 24.04 * PostgreSQL version: `16.14` * Database backend: PostgreSQL * PostgreSQL address: `127.0.0.1:5433` * PostgreSQL database: `xui` * Installation type: native systemd installation * Service file: `/etc/systemd/system/x-ui.service` * Environment file: `/etc/default/x-ui` * Root filesystem size: approximately 19 GB Sensitive database credentials, public IP addresses, usernames, and hostnames have been removed from this report. --- ## Initial user-visible behavior The management menu showed: ```text Panel state: Not Running Start automatically: Yes xray state: Not Running ``` Selecting **Start** produced: ```text [ERR] panel Failed to start, Probably because it takes longer than two seconds to start, Please check the log information later ``` Restarting produced: ```text [ERR] Panel restart failed, Probably because it takes longer than two seconds to start, Please check the log information later ``` This message suggested a startup timing problem, but the service was actually exiting with status 1 almost immediately. --- ## Actual service failure `systemctl status x-ui` showed: ```text Active: activating (auto-restart) (Result: exit-code) Process: ... ExecStart=/usr/local/x-ui/x-ui (code=exited, status=1/FAILURE) Main PID: ... (code=exited, status=1/FAILURE) ``` The real error appeared only after manually running: ```bash journalctl -u x-ui -n 100 --no-pager ``` The relevant message was: ```text Starting x-ui 3.5.0 Error initializing database: failed to connect to `user=[REDACTED] database=xui`: 127.0.0.1:5433: FATAL: the database system is in recovery mode (SQLSTATE 57P03) ``` At other times during the incident, the database error was: ```text FATAL: the database system is shutting down (SQLSTATE 57P03) ``` The panel could not initialize its database and exited. Xray therefore did not start under the x-ui service. --- ## Root cause The root filesystem had reached 100% usage: ```text Filesystem Size Used Avail Use% Mounted on /dev/vda1 19G 19G 0 100% / ``` PostgreSQL attempted a checkpoint and failed: ```text PANIC: could not write to file "pg_logical/replorigin_checkpoint.tmp": No space left on device ``` PostgreSQL then terminated its server processes and entered automatic crash recovery: ```text checkpointer process was terminated by signal 6: Aborted terminating any other active server processes database system was not properly shut down automatic recovery in progress ``` While PostgreSQL was unavailable, x-ui continued restarting every five seconds because the service contained: ```ini Restart=on-failure RestartSec=5s ``` There was no practical restart burst limit in the service configuration. The restart counter reached at least: ```text restart counter is at 130 ``` --- ## Log amplification The full filesystem had multiple contributors, including SSH brute-force records and another verbose service. However, x-ui’s failure loop significantly amplified the incident. The largest logs included: ```text 772M /var/log/kern.log 275M /var/log/syslog 269M /var/log/btmp 244M /var/log/auth.log ``` When I counted program names in `kern.log`, I found: ```text 4023499 /usr/local/x-ui/x-ui 3795 kernel ``` In other words, more than four million entries in `kern.log` were attributed to the x-ui executable. The default rsyslog configuration was normal: ```text *.*;auth,authpriv.none -/var/log/syslog kern.* -/var/log/kern.log ``` This means x-ui’s userspace messages appear to have been submitted with a kernel syslog facility, or otherwise classified as `kern.*`. Example entries found in `kern.log`: ```text /usr/local/x-ui/x-ui[PID]: INFO - GC percent set to 75 /usr/local/x-ui/x-ui[PID]: INFO - Go memory soft limit not enforced ``` A userspace panel process should not normally generate millions of entries in the kernel log. --- ## PostgreSQL status was also misleading On Debian/Ubuntu, this command showed: ```bash systemctl status postgresql ``` ```text postgresql.service - PostgreSQL RDBMS Active: active (exited) ``` That wrapper unit looked healthy even though the actual PostgreSQL cluster was stuck. The relevant unit was: ```bash systemctl status postgresql@16-main ``` It showed: ```text Active: deactivating (stop-sigterm) (Result: exit-code) ``` The PostgreSQL process list contained a stuck cluster process and checkpointer. Therefore, checking only `postgresql.service` is insufficient on Debian-based systems. Diagnostics should identify the actual cluster unit, for example through `pg_lsclusters`. --- ## Recovery steps used ### 1. Stop the x-ui restart loop I temporarily masked the service: ```bash systemctl mask --runtime --now x-ui ``` This stopped further restart attempts without permanently disabling autostart. ### 2. Free disk space I identified the largest logs and cleared the accumulated files after preserving diagnostic samples. After cleanup: ```text Filesystem Size Used Avail Use% Mounted on /dev/vda1 19G 12G 6.3G 66% / ``` ### 3. Stop the stuck PostgreSQL cluster A normal stop did not complete: ```text pg_ctl: server does not shut down ``` The cluster remained in `deactivating` state for more than 15 minutes. An immediate PostgreSQL shutdown signal was then sent through systemd: ```bash systemctl kill \ --kill-whom=all \ --signal=SIGQUIT \ postgresql@16-main ``` This is an emergency recovery action, not something that should normally be required. PostgreSQL then performed automatic crash recovery: ```text database system was not properly shut down automatic recovery in progress redo starts at ... redo done at ... checkpoint complete: end-of-recovery database system is ready to accept connections ``` ### 4. Verify PostgreSQL ```bash pg_isready -h 127.0.0.1 -p 5433 ``` Result: ```text 127.0.0.1:5433 - accepting connections ``` Recovery status: ```bash sudo -u postgres psql -p 5433 -Atc \ 'SELECT pg_is_in_recovery();' ``` Result: ```text f ``` ### 5. Start x-ui again ```bash systemctl unmask x-ui systemctl reset-failed x-ui systemctl start x-ui ``` The service then started successfully: ```text Active: active (running) Web server running HTTPS on 0.0.0.0:2087 Sub server running HTTPS on 0.0.0.0:2096 Xray 26.7.11 started ``` The management menu finally showed: ```text Panel state: Running Start automatically: Yes xray state: Running ``` No database restoration was required, and no database corruption was detected after recovery. --- # Problems in the current behavior ## 1. The two-second check produces a misleading diagnosis The current start/restart flow effectively performs: ```bash systemctl start x-ui sleep 2 check_status ``` If the process is not running, it says that startup probably took longer than two seconds. This does not distinguish between: * service still activating; * process exited with status 1; * PostgreSQL unavailable; * invalid database credentials; * database in recovery; * database shutting down; * port conflict; * invalid configuration; * missing certificate; * filesystem full; * binary crash. In this incident, the process had already exited. Waiting longer would never have fixed it. ## 2. The real error is hidden The management script tells the user to check logs later but does not print the relevant logs or provide the exact command. Many users will not know to run: ```bash systemctl status x-ui --no-pager -l journalctl -u x-ui -n 50 --no-pager ``` The script already has enough context to display these automatically. ## 3. Unlimited automatic retries create a log storm A five-second restart interval without an effective burst limit means approximately: ```text 12 restart attempts per minute 720 restart attempts per hour 17,280 restart attempts per day ``` A persistent dependency failure can therefore create enormous logs and unnecessary CPU/process churn. ## 4. PostgreSQL dependency health is not checked If the configured backend is PostgreSQL, the management script does not appear to check whether the configured PostgreSQL endpoint is reachable before starting the panel. It also does not recognize common PostgreSQL states such as: ```text SQLSTATE 57P03 database system is starting up database system is in recovery mode database system is shutting down ``` ## 5. The database wrapper service can give a false healthy result On Ubuntu, `postgresql.service` is a wrapper and may report `active (exited)` while the real cluster is unhealthy. The script should inspect: ```bash pg_lsclusters systemctl status postgresql@VERSION-CLUSTER pg_isready ``` when using a local PostgreSQL installation. ## 6. x-ui messages were written into `kern.log` More than four million x-ui messages were present in `/var/log/kern.log`. The application’s syslog facility should be reviewed. Userspace application logs should use an appropriate facility such as: * `daemon`; * `user`; * `local0`; * or normal stderr/stdout captured by journald. They should not be classified as kernel messages. ## 7. Global Xray process detection may be inaccurate The script appears to determine Xray status by globally searching for an `xray-linux` process. On servers where another panel or service also runs Xray, this can report: ```text xray state: Running ``` even if the Xray instance belonging to 3X-UI is not running. Xray status should be scoped to: * the x-ui systemd cgroup; * the child PID started by x-ui; * a PID file; * or the specific configured executable and parent PID. --- # Suggested improvements ## A. Replace the fixed two-second sleep with a bounded service-state loop Example logic: ```bash wait_for_xui() { local timeout="${1:-30}" local elapsed=0 while (( elapsed < timeout )); do if systemctl is-active --quiet x-ui; then return 0 fi if systemctl is-failed --quiet x-ui; then return 1 fi sleep 1 ((elapsed++)) done return 2 } ``` The result could distinguish: * `0`: started successfully; * `1`: exited or failed; * `2`: still activating after timeout. ## B. Print immediate diagnostics on failure When start or restart fails, automatically show: ```bash systemctl status x-ui --no-pager -l journalctl -u x-ui -n 30 --no-pager ``` The output should preferably be filtered to the current boot or current invocation: ```bash journalctl -u x-ui -b -n 30 --no-pager ``` The script should print the actual `ExecMainStatus` and service result: ```bash systemctl show x-ui \ -p ActiveState \ -p SubState \ -p Result \ -p ExecMainCode \ -p ExecMainStatus ``` Example user-facing output: ```text Panel failed to start. Service result: exit-code Exit status: 1 Last error: Error initializing database: FATAL: the database system is in recovery mode Suggested action: Check PostgreSQL availability and available disk space. ``` ## C. Add PostgreSQL preflight diagnostics When `XUI_DB_TYPE=postgres`, the script should read the configured DSN from the environment file and test the database host and port without printing the password. Possible checks: ```bash pg_isready -h "$db_host" -p "$db_port" -d "$db_name" ``` If `pg_isready` is unavailable, a TCP connectivity test could be used as a fallback. The script should not log the full DSN because it contains credentials. Recognized error states should include: ```text SQLSTATE 57P03 database system is starting up database system is in recovery mode database system is shutting down connection refused password authentication failed no pg_hba.conf entry ``` ## D. Detect disk exhaustion automatically When PostgreSQL or x-ui fails, the diagnostic routine should run: ```bash df -P / df -i / ``` If any relevant filesystem is near capacity, show a prominent warning: ```text Critical: filesystem / is 100% full. PostgreSQL cannot complete checkpoints or crash recovery without free disk space. Free space before restarting x-ui repeatedly. ``` It could also search recent PostgreSQL logs for: ```text No space left on device could not write to file PANIC checkpoint ``` ## E. Inspect the real PostgreSQL cluster on Debian/Ubuntu For a locally installed PostgreSQL server: ```bash pg_lsclusters --no-header ``` Then inspect the actual cluster service: ```bash systemctl status "postgresql@${version}-${cluster}" ``` Do not rely only on: ```bash systemctl status postgresql ``` because that unit may be `active (exited)` while a cluster is unavailable. ## F. Stop automatic retries when a persistent dependency failure is detected The script could stop the service after detecting a PostgreSQL failure: ```bash systemctl stop x-ui systemctl reset-failed x-ui ``` It should tell the user that x-ui was stopped to prevent a restart/log loop. A temporary runtime mask could optionally be offered: ```bash systemctl mask --runtime x-ui ``` This should not be applied silently, but it could be presented as an interactive recovery option. ## G. Add systemd restart limits A safer service configuration would include something similar to: ```ini [Unit] StartLimitIntervalSec=300 StartLimitBurst=5 [Service] Restart=on-failure RestartSec=30s ``` This allows recovery from temporary failures but prevents indefinite five-second loops. Another option is exponential or progressively increasing restart backoff if supported by the target systemd versions. ## H. Add application-level database retry/backoff Instead of exiting immediately after one failed connection, the backend could retry PostgreSQL initialization with bounded exponential backoff. Example behavior: ```text Database unavailable: PostgreSQL is in recovery. Retrying in 5 seconds... Retrying in 10 seconds... Retrying in 20 seconds... ``` After a reasonable timeout, it could exit with one clear final error. This would avoid hundreds of complete process restarts for a short PostgreSQL recovery. ## I. Correct the logging facility Please audit how x-ui submits logs to syslog/journald. Messages such as: ```text INFO - GC percent set to 75 INFO - Go memory soft limit not enforced ``` should not be written with the `kern` facility. Recommended behavior: * write structured logs to stdout/stderr under systemd; * or use a userspace syslog facility; * rely on journald and log rotation; * avoid duplicating the same output into multiple large files. ## J. Add an `x-ui doctor` command A diagnostic command could test: ```text - x-ui binary and permissions - systemd service state and exit status - configured database backend - PostgreSQL connectivity - local PostgreSQL cluster state - filesystem and inode usage - panel and subscription ports - certificate file existence and permissions - Xray configuration validation - Xray process ownership - last relevant logs ``` Example: ```bash x-ui doctor ``` Possible output: ```text [OK] x-ui binary found [FAIL] PostgreSQL 127.0.0.1:5433 is not ready [FAIL] Root filesystem is 100% full [WARN] x-ui has restarted 126 times [WARN] 772 MB kern.log contains repeated x-ui entries Primary diagnosis: PostgreSQL crashed because the filesystem is full. x-ui has been stopped to prevent further restart attempts. ``` ## K. Scope Xray status to the x-ui service Instead of a global process search, use a service-scoped check such as: ```bash systemctl show x-ui -p MainPID systemctl status x-ui systemd-cgls /system.slice/x-ui.service ``` Or track the exact Xray child process started by the panel. This avoids reporting another application’s Xray process as the 3X-UI Xray process. --- # Expected behavior When the panel fails because PostgreSQL is unavailable, the management script should provide an actionable message such as: ```text 3X-UI could not start because its PostgreSQL database is unavailable. Database: Host: 127.0.0.1 Port: 5433 Name: xui PostgreSQL response: FATAL: the database system is in recovery mode SQLSTATE: 57P03 Filesystem: / is 100% full The x-ui service has been stopped to prevent an automatic restart loop. Recommended steps: 1. Free disk space. 2. Verify the PostgreSQL cluster. 3. Run: x-ui start ``` It should not describe this situation as probably taking longer than two seconds. --- # Proposed acceptance criteria 1. A failed process exit is distinguished from a slow startup. 2. Start/restart failures show the actual systemd result and recent logs. 3. PostgreSQL configurations receive a database connectivity preflight. 4. SQLSTATE `57P03` produces a database-specific explanation. 5. Disk and inode usage are checked after database-related failures. 6. The default service cannot restart forever every five seconds. 7. x-ui userspace logs no longer enter `kern.log`. 8. Xray status is scoped to the x-ui-managed process. 9. Debian/Ubuntu diagnostics inspect the real PostgreSQL cluster unit. 10. A diagnostic or doctor command can summarize the likely root cause. --- ## Final result after manual recovery After freeing disk space, recovering PostgreSQL, and restarting x-ui: ```text PostgreSQL: accepting connections pg_is_in_recovery(): false Panel state: Running Start automatically: Yes xray state: Running ``` The panel, subscription server, and Xray core all started successfully. This incident was ultimately recoverable, but the management script’s generic message and the unbounded restart loop made the failure much harder to diagnose and significantly increased log volume. Better dependency diagnostics and restart controls would make this class of incident much safer for other users. ### How to reproduce the problem Actual service failure systemctl status x-ui showed: Active: activating (auto-restart) (Result: exit-code) Process: ... ExecStart=/usr/local/x-ui/x-ui (code=exited, status=1/FAILURE) Main PID: ... (code=exited, status=1/FAILURE) The real error appeared only after manually running: journalctl -u x-ui -n 100 --no-pager The relevant message was: Starting x-ui 3.5.0 Error initializing database: failed to connect to `user=[REDACTED] database=xui`: 127.0.0.1:5433: FATAL: the database system is in recovery mode (SQLSTATE 57P03) At other times during the incident, the database error was: FATAL: the database system is shutting down (SQLSTATE 57P03) The panel could not initialize its database and exited. Xray therefore did not start under the x-ui service. Root cause The root filesystem had reached 100% usage: Filesystem Size Used Avail Use% Mounted on /dev/vda1 19G 19G 0 100% / PostgreSQL attempted a checkpoint and failed: PANIC: could not write to file "pg_logical/replorigin_checkpoint.tmp": No space left on device PostgreSQL then terminated its server processes and entered automatic crash recovery: checkpointer process was terminated by signal 6: Aborted terminating any other active server processes database system was not properly shut down automatic recovery in progress While PostgreSQL was unavailable, x-ui continued restarting every five seconds because the service contained: Restart=on-failure RestartSec=5s There was no practical restart burst limit in the service configuration. The restart counter reached at least: restart counter is at 130 Log amplification The full filesystem had multiple contributors, including SSH brute-force records and another verbose service. However, x-ui’s failure loop significantly amplified the incident. The largest logs included: 772M /var/log/kern.log 275M /var/log/syslog 269M /var/log/btmp 244M /var/log/auth.log When I counted program names in kern.log, I found: 4023499 /usr/local/x-ui/x-ui 3795 kernel In other words, more than four million entries in kern.log were attributed to the x-ui executable. The default rsyslog configuration was normal: *.*;auth,authpriv.none -/var/log/syslog kern.* -/var/log/kern.log This means x-ui’s userspace messages appear to have been submitted with a kernel syslog facility, or otherwise classified as kern.*. Example entries found in kern.log: /usr/local/x-ui/x-ui[PID]: INFO - GC percent set to 75 /usr/local/x-ui/x-ui[PID]: INFO - Go memory soft limit not enforced A userspace panel process should not normally generate millions of entries in the kernel log. PostgreSQL status was also misleading On Debian/Ubuntu, this command showed: systemctl status postgresql postgresql.service - PostgreSQL RDBMS Active: active (exited) That wrapper unit looked healthy even though the actual PostgreSQL cluster was stuck. The relevant unit was: systemctl status postgresql@16-main It showed: Active: deactivating (stop-sigterm) (Result: exit-code) The PostgreSQL process list contained a stuck cluster process and checkpointer. Therefore, checking only postgresql.service is insufficient on Debian-based systems. Diagnostics should identify the actual cluster unit, for example through pg_lsclusters. ### Expected behavior _No response_ ### Actual behavior Initial user-visible behavior The management menu showed: Panel state: Not Running Start automatically: Yes xray state: Not Running Selecting Start produced: [ERR] panel Failed to start, Probably because it takes longer than two seconds to start, Please check the log information later Restarting produced: [ERR] Panel restart failed, Probably because it takes longer than two seconds to start, Please check the log information later This message suggested a startup timing problem, but the service was actually exiting with status 1 almost immediately. ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.5.0 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system linux ubuntu 22 ### Which parts of the panel are affected? _No response_ ### 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:37:43 +07:00
Author
Owner

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

Investigated against v3.5.0 (current latest release, and nothing since addresses this). The report is accurate; two items are confirmed defects with a clear root cause, and the rest are legitimate gaps rather than bugs in existing behavior. Details below, each grounded in the file and line checked.

Title: Syslog backend logs everything under the kernel facility, so panel output lands in kern.log

Severity: Medium

Category: Correctness

Why this matters: internal/logger/logger.go:85 calls logging.NewSyslogBackend("") from the pinned dependency github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 (go.mod:18). The implementation of NewSyslogBackend is syslog.New(syslog.LOG_CRIT, prefix), and LOG_CRIT is a severity-only constant with no facility bits set. In the stdlib log/syslog package (writeAndRetry: pr := (w.priority & facilityMask) | (p & severityMask)), the facility of every subsequent write comes from the priority passed to New(); with no facility bits set, that defaults to LOG_KERN (facility 0). So every line the panel logs, Info, Warning, Error, all of it, is submitted to the local syslog socket tagged as a kernel message, independent of its real severity. Against the default Debian/Ubuntu rsyslog rule quoted in this report (kern.* -/var/log/kern.log), that routes the entire log output of the panel into kern.log. This matches the report precisely: the INFO - GC percent set to 75 / INFO - Go memory soft limit not enforced lines found in kern.log come from logger.Info(line) in main.go:56-58 (fed by sys.ApplyMemoryTuning()), which goes through this backend, while the Error initializing database: ... message that only showed up in journalctl -u x-ui is printed via the stdlib log.Fatalf at main.go:71, which bypasses this backend and goes straight to stderr/journal. Nothing here is Docker- or install-method-specific; any systemd/local-syslog install with a default rsyslog config is affected.

Recommendation: pass an explicit non-kernel facility. The same dependency also exports NewSyslogBackendPriority(prefix string, priority syslog.Priority), so initDefaultBackend (internal/logger/logger.go:75-95) could call it with a syslog.LOG_DAEMON-based priority instead of NewSyslogBackend(""). A fix will only be made if a maintainer requests it by mentioning @claude.

Title: Shipped systemd units have no effective restart-attempt limit

Severity: Medium

Category: Reliability

Why this matters: x-ui.service.debian, x-ui.service.rhel, and x-ui.service.arch all set Restart=on-failure / RestartSec=5s and none set StartLimitIntervalSec= / StartLimitBurst= in [Unit]. The documented systemd default start-limit window (DefaultStartLimitIntervalSec=10s, DefaultStartLimitBurst=5, from systemd-system.conf) is what would normally stop a crash-looping unit, but at a fixed 5-second RestartSec only about two start attempts fall inside any rolling 10-second window, never reaching the default burst of 5, so the unit is never placed into start-limit-hit and restarts indefinitely. That lines up with the reported "restart counter is at 130" while the service stayed in activating (auto-restart). This is independent of the application: even a non-transient failure such as a bad DSN or missing credentials will restart every 5 seconds forever.

Recommendation: add explicit StartLimitIntervalSec=/StartLimitBurst= to [Unit] in the three x-ui.service.* files, as suggestion G in the report proposes. A fix will only be made if a maintainer requests it by mentioning @claude.

Also confirmed directly against the source (accurate gaps, not defects, enhancement territory, corresponding to suggestions A-D, H, J, K in the report):

  • The generic "probably takes longer than two seconds" message is unconditional: start()/restart() in x-ui.sh (lines 493-597) run systemctl start|restart x-ui, sleep 2, then check_status, and print that fixed string (x-ui.sh:518, :592) whenever check_status does not see running. check_status (x-ui.sh:863-894) only greps the Active line for the word running; it never reads ExecMainStatus/Result, so "still starting", "exited immediately", and "crash-looping" are indistinguishable to the script.
  • No log output is surfaced automatically on failure; the LOGE calls in those same functions never invoke journalctl/systemctl status.
  • There is no PostgreSQL preflight or connectivity check anywhere in x-ui.sh, and no SQLSTATE-aware handling in the Go startup path; a search for SQLSTATE/57P03/pgconn across internal/ turns up only one unrelated hit, a deadlock-retry comment in internal/web/service/traffic_writer.go:120.
  • There is no disk or inode usage check anywhere in x-ui.sh (suggestion D).
  • database.InitDB (internal/database/db.go:1750) returns the raw driver error on the first failure, and main.go:69-71 calls log.Fatalf immediately; there is no retry/backoff before the process exits (suggestion H).
  • check_xray_status() (x-ui.sh:973-980) runs an unscoped ps -ef | grep "xray-linux", with no PID file, cgroup, or parent-PID scoping (suggestion K).
  • There is no x-ui doctor or equivalent diagnostic subcommand; the CLI only defines run, migrate, migrate-db, setting, and cert (main.go:593-679, suggestion J).
  • The distinction between the postgresql.service wrapper and postgresql@<version>-<cluster> (suggestion E) is accurate general behavior of the postgresql-common packaging used on Debian/Ubuntu, not something in this repository; worth acting on, but outside the current scope of x-ui.sh.
  • The same restart-storm/no-backoff gap applies to the Docker path too: the 3xui and postgres services in docker-compose.yml have no depends_on/healthcheck coupling, and restart: unless-stopped has no burst limiting either.

Given this bundles a couple of confirmed defects with a larger set of reasonable reliability and tooling requests, the bug label stays and enhancement is being added.

Fixes are not applied here; this is a read-only triage pass. @MHSanaei for visibility and to decide on scope and priority, since addressing this touches the install script, all three systemd unit files, and the Go startup/logging path.

This reply was generated automatically by an AI agent. A maintainer may follow up.

<!-- gh-comment-id:5009374866 --> @github-actions[bot] commented on GitHub (Jul 18, 2026): Investigated against `v3.5.0` (current latest release, and nothing since addresses this). The report is accurate; two items are confirmed defects with a clear root cause, and the rest are legitimate gaps rather than bugs in existing behavior. Details below, each grounded in the file and line checked. Title: Syslog backend logs everything under the kernel facility, so panel output lands in `kern.log` Severity: Medium Category: Correctness Why this matters: `internal/logger/logger.go:85` calls `logging.NewSyslogBackend("")` from the pinned dependency `github.com/op/go-logging v0.0.0-20160315200505-970db520ece7` (`go.mod:18`). The implementation of `NewSyslogBackend` is `syslog.New(syslog.LOG_CRIT, prefix)`, and `LOG_CRIT` is a severity-only constant with no facility bits set. In the stdlib `log/syslog` package (`writeAndRetry`: `pr := (w.priority & facilityMask) | (p & severityMask)`), the facility of every subsequent write comes from the priority passed to `New()`; with no facility bits set, that defaults to `LOG_KERN` (facility 0). So every line the panel logs, Info, Warning, Error, all of it, is submitted to the local syslog socket tagged as a kernel message, independent of its real severity. Against the default Debian/Ubuntu rsyslog rule quoted in this report (`kern.* -/var/log/kern.log`), that routes the entire log output of the panel into `kern.log`. This matches the report precisely: the `INFO - GC percent set to 75` / `INFO - Go memory soft limit not enforced` lines found in `kern.log` come from `logger.Info(line)` in `main.go:56-58` (fed by `sys.ApplyMemoryTuning()`), which goes through this backend, while the `Error initializing database: ...` message that only showed up in `journalctl -u x-ui` is printed via the stdlib `log.Fatalf` at `main.go:71`, which bypasses this backend and goes straight to stderr/journal. Nothing here is Docker- or install-method-specific; any systemd/local-syslog install with a default rsyslog config is affected. Recommendation: pass an explicit non-kernel facility. The same dependency also exports `NewSyslogBackendPriority(prefix string, priority syslog.Priority)`, so `initDefaultBackend` (`internal/logger/logger.go:75-95`) could call it with a `syslog.LOG_DAEMON`-based priority instead of `NewSyslogBackend("")`. A fix will only be made if a maintainer requests it by mentioning @claude. Title: Shipped systemd units have no effective restart-attempt limit Severity: Medium Category: Reliability Why this matters: `x-ui.service.debian`, `x-ui.service.rhel`, and `x-ui.service.arch` all set `Restart=on-failure` / `RestartSec=5s` and none set `StartLimitIntervalSec=` / `StartLimitBurst=` in `[Unit]`. The documented systemd default start-limit window (`DefaultStartLimitIntervalSec=10s`, `DefaultStartLimitBurst=5`, from `systemd-system.conf`) is what would normally stop a crash-looping unit, but at a fixed 5-second `RestartSec` only about two start attempts fall inside any rolling 10-second window, never reaching the default burst of 5, so the unit is never placed into `start-limit-hit` and restarts indefinitely. That lines up with the reported "restart counter is at 130" while the service stayed in `activating (auto-restart)`. This is independent of the application: even a non-transient failure such as a bad DSN or missing credentials will restart every 5 seconds forever. Recommendation: add explicit `StartLimitIntervalSec=`/`StartLimitBurst=` to `[Unit]` in the three `x-ui.service.*` files, as suggestion G in the report proposes. A fix will only be made if a maintainer requests it by mentioning @claude. Also confirmed directly against the source (accurate gaps, not defects, enhancement territory, corresponding to suggestions A-D, H, J, K in the report): - The generic "probably takes longer than two seconds" message is unconditional: `start()`/`restart()` in `x-ui.sh` (lines 493-597) run `systemctl start|restart x-ui`, `sleep 2`, then `check_status`, and print that fixed string (`x-ui.sh:518`, `:592`) whenever `check_status` does not see `running`. `check_status` (`x-ui.sh:863-894`) only greps the `Active` line for the word `running`; it never reads `ExecMainStatus`/`Result`, so "still starting", "exited immediately", and "crash-looping" are indistinguishable to the script. - No log output is surfaced automatically on failure; the `LOGE` calls in those same functions never invoke `journalctl`/`systemctl status`. - There is no PostgreSQL preflight or connectivity check anywhere in `x-ui.sh`, and no SQLSTATE-aware handling in the Go startup path; a search for `SQLSTATE`/`57P03`/`pgconn` across `internal/` turns up only one unrelated hit, a deadlock-retry comment in `internal/web/service/traffic_writer.go:120`. - There is no disk or inode usage check anywhere in `x-ui.sh` (suggestion D). - `database.InitDB` (`internal/database/db.go:1750`) returns the raw driver error on the first failure, and `main.go:69-71` calls `log.Fatalf` immediately; there is no retry/backoff before the process exits (suggestion H). - `check_xray_status()` (`x-ui.sh:973-980`) runs an unscoped `ps -ef | grep "xray-linux"`, with no PID file, cgroup, or parent-PID scoping (suggestion K). - There is no `x-ui doctor` or equivalent diagnostic subcommand; the CLI only defines `run`, `migrate`, `migrate-db`, `setting`, and `cert` (`main.go:593-679`, suggestion J). - The distinction between the `postgresql.service` wrapper and `postgresql@<version>-<cluster>` (suggestion E) is accurate general behavior of the `postgresql-common` packaging used on Debian/Ubuntu, not something in this repository; worth acting on, but outside the current scope of `x-ui.sh`. - The same restart-storm/no-backoff gap applies to the Docker path too: the `3xui` and `postgres` services in `docker-compose.yml` have no `depends_on`/healthcheck coupling, and `restart: unless-stopped` has no burst limiting either. Given this bundles a couple of confirmed defects with a larger set of reasonable reliability and tooling requests, the `bug` label stays and `enhancement` is being added. Fixes are not applied here; this is a read-only triage pass. @MHSanaei for visibility and to decide on scope and priority, since addressing this touches the install script, all three systemd unit files, and the Go startup/logging path. *This reply was generated automatically by an AI agent. A maintainer may follow up.*
Author
Owner

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

Fixed in #6083. The initial PostgreSQL connection now retries with backoff and logs the real error, and the systemd units carry StartLimit* so an unreachable DB stops the unit instead of looping.

<!-- gh-comment-id:5059095967 --> @MHSanaei commented on GitHub (Jul 23, 2026): Fixed in #6083. The initial PostgreSQL connection now retries with backoff and logs the real error, and the systemd units carry StartLimit* so an unreachable DB stops the unit instead of looping.
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#4171
No description provided.