Skip to content

Tunnel inbound: Fix panic when listening on UDS for Xray's internal services (e.g. API) - #6062

Merged
RPRX merged 2 commits into
XTLS:mainfrom
MakostaDev:fix-tunnel-unix-socket
May 2, 2026
Merged

RPRX merged 2 commits into
XTLS:mainfrom
MakostaDev:fix-tunnel-unix-socket

Conversation

@MakostaDev

Copy link
Copy Markdown
Contributor

fixed a panic that occurs when using UNIX socket as the listen address in dokodemo-door inbound configuration:

panic: strconv.Atoi: parsing "": invalid syntax

goroutine 51 [running]:
github.com/xtls/xray-core/common.Must(...)
        github.com/xtls/xray-core/common/common.go:22
github.com/xtls/xray-core/common.Must2[...](...)
        github.com/xtls/xray-core/common/common.go:30
github.com/xtls/xray-core/proxy/dokodemo.(*DokodemoDoor).Process(0x3dc6317d7140, {0x16255b0, 0x3dc6318780c0}, 0x4, {0x7fa901fb91a0, 0x3dc6314b20b8}, {0x162a220, 0x3dc63159b710})
        github.com/xtls/xray-core/proxy/dokodemo/dokodemo.go:99 +0x11f1
github.com/xtls/xray-core/app/proxyman/inbound.(*dsWorker).callback(0x3dc631874b60, {0x7fa901fb91a0, 0x3dc6314b20b8})
        github.com/xtls/xray-core/app/proxyman/inbound/worker.go:510 +0x484
created by github.com/xtls/xray-core/app/proxyman/inbound.(*dsWorker).Start.func1 in goroutine 50
        github.com/xtls/xray-core/app/proxyman/inbound/worker.go:530 +0x7a

when using UNIX socket, the net.SplitHostPort() function returns an empty string for the port variable. at line 99, the code attempts to convert this empty string to an integer using strconv.Atoi(port), which causes the panic.
my example configuration:

{
    "protocol": "dokodemo-door",
    "listen": "/my/path/api.sock,0666",
    "tag": "api"
}

@RPRX

RPRX commented May 2, 2026

Copy link
Copy Markdown
Member

那你这流量准备发到哪,靠 Freedom 出站的 redirect 吗

@MakostaDev

Copy link
Copy Markdown
Contributor Author

the traffic is intended to be processed by the internal gRPC API
here is my configuration:

{
    "inbounds": [
        {
            "protocol": "dokodemo-door",
            "listen": "/my/path/api.sock,0666",
            "tag": "api"
        }
    ],
    "api": {
        "tag": "api",
        "services": [
            "LoggerService",
            "RoutingService",
            "HandlerService"
        ]
    },
    "routing": {
        "rules": [
            {
                "inboundTag": ["api"],
                "outboundTag": "api"
            }
        ]
    }
}

I tested it and еverything works perfectly on my end with this configuration and the fix

@RPRX RPRX changed the title Fix: panic when using UNIX socket in tunnel (dokodemo-door) Tunnel inbound: Fix panic when listening on UDS for Xray's internal services (e.g. API) May 2, 2026
@MakostaDev

MakostaDev commented May 2, 2026 •

Copy link
Copy Markdown
Contributor Author

While exploring the XRAY-core internals, I noticed that the API listener currently uses the standard net.Listen from golang. Although net.Listen itself supports Unix sockets, I found it more appropriate to use XRAY's internal listener wrapper instead.
I've updated the implementation to use XRAY's internal listener wrapper instead. This wrapper is more versatile as it handles both TCP and UNIX sockets automatically, including file mode settings. This change makes the API listening logic consistent with the rest of the project and enables native UNIX socket support for the API block

@RPRX

RPRX commented May 2, 2026

Copy link
Copy Markdown
Member

I've updated the implementation to use XRAY's internal listener wrapper instead

处理 @@ 的代码也在里面对吧

@RPRX

RPRX commented May 2, 2026

Copy link
Copy Markdown
Member

看到了,有包含 @@

@MakostaDev

MakostaDev commented May 2, 2026 •

Copy link
Copy Markdown
Contributor Author

I've updated the implementation to use XRAY's internal listener wrapper instead

处理 @@ 的代码也在里面对吧

Yes. Btw, unlike net.Listen, this wrapper has supports @@

@RPRX
RPRX merged commit e61eeae into XTLS:main May 2, 2026
39 checks passed
@MakostaDev
MakostaDev deleted the fix-tunnel-unix-socket branch May 3, 2026 05:41
BobJustFry pushed a commit to BobJustFry/xray-core that referenced this pull request Jun 7, 2026
…ervices (e.g. API) (XTLS#6062)

And API supports listening on UNIX domain socket directly

Completes XTLS#5693
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants