[GH-ISSUE #19] tun2socks fails to start: wrong flag syntax -config instead of --config #13

Open
opened 2026-10-31 21:01:47 +00:00 by bsakaguchi · 0 comments
Owner

Originally created by @tqb333 on GitHub (Aug 1, 2026).
Original GitHub issue: https://github.com/MrTheory/os-xray/issues/19

tun2socks never starts — xray-service-control.php invokes it with -config (single dash), which pflag/Cobra doesn't recognize as --config

Environment: OPNsense 26.7.1 (FreeBSD 15.1 amd64), os-xray v3.0.0, tun2socks v2.7.0, xray-core v26.3.27

Description

After a clean install and a correctly configured instance (wizard fields all valid, confirmed working via manual SOCKS5 test), xray-core starts fine but tun2socks never comes up. configctl xray statusall (and the GUI status page) shows:

{"<uuid>":{"name":"default","status":"stopped","xray_core":"running","tun2socks":"stopped"}}

indefinitely, with no error surfaced to the user.

Root cause

scripts/Xray/xray-service-control.php, in do_start():

proc_start(T2S_BIN, '-config ' . escapeshellarg(t2s_conf_path($inst_uuid)), t2s_pid_path($inst_uuid), $instLog);

tun2socks uses pflag/Cobra for CLI parsing (-c, --config string per its own --help). pflag treats a single dash followed by a multi-character name as a cluster of shorthand flags, not as the long-form flag — so -config is not equivalent to --config. The process either fails to parse its config path correctly or exits immediately; either way it never comes up, and the failure isn't logged anywhere visible.

Steps to reproduce

  1. Install the plugin, configure a valid VLESS+Reality instance (wizard or via the "existing config" auto-import path).
  2. Start the instance.
  3. xray-core shows running; tun2socks shows stopped; the TUN interface never comes up.

Verification of the fix

Running the exact same binary/config manually with the corrected flag works immediately:

/usr/local/tun2socks/tun2socks --config /usr/local/tun2socks/config-<uuid>.yaml

brings the TUN interface up right away, whereas the same invocation with -config does not.

Suggested fix

Change '-config ' to '--config ' (or '-c ') in xray-service-control.php.

Originally created by @tqb333 on GitHub (Aug 1, 2026). Original GitHub issue: https://github.com/MrTheory/os-xray/issues/19 tun2socks never starts — `xray-service-control.php` invokes it with `-config` (single dash), which pflag/Cobra doesn't recognize as `--config` **Environment:** OPNsense 26.7.1 (FreeBSD 15.1 amd64), os-xray v3.0.0, tun2socks v2.7.0, xray-core v26.3.27 **Description** After a clean install and a correctly configured instance (wizard fields all valid, confirmed working via manual SOCKS5 test), `xray-core` starts fine but `tun2socks` never comes up. `configctl xray statusall` (and the GUI status page) shows: ```json {"<uuid>":{"name":"default","status":"stopped","xray_core":"running","tun2socks":"stopped"}} ``` indefinitely, with no error surfaced to the user. **Root cause** `scripts/Xray/xray-service-control.php`, in `do_start()`: ```php proc_start(T2S_BIN, '-config ' . escapeshellarg(t2s_conf_path($inst_uuid)), t2s_pid_path($inst_uuid), $instLog); ``` `tun2socks` uses pflag/Cobra for CLI parsing (`-c, --config string` per its own `--help`). pflag treats a single dash followed by a multi-character name as a *cluster of shorthand flags*, not as the long-form flag — so `-config` is not equivalent to `--config`. The process either fails to parse its config path correctly or exits immediately; either way it never comes up, and the failure isn't logged anywhere visible. **Steps to reproduce** 1. Install the plugin, configure a valid VLESS+Reality instance (wizard or via the "existing config" auto-import path). 2. Start the instance. 3. `xray-core` shows running; `tun2socks` shows stopped; the TUN interface never comes up. **Verification of the fix** Running the exact same binary/config manually with the corrected flag works immediately: ``` /usr/local/tun2socks/tun2socks --config /usr/local/tun2socks/config-<uuid>.yaml ``` brings the TUN interface up right away, whereas the same invocation with `-config` does not. **Suggested fix** Change `'-config '` to `'--config '` (or `'-c '`) in `xray-service-control.php`.
Sign in to join this conversation.
No labels
pull-request
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
MrTheory/os-xray#13
No description provided.