[Bug] check_port in util.sh fails when restserver.url has no scheme prefix
Bug Type (问题类型)
other exception / error (其他异常报错)
Before submit
- [x] 我已经确认现有的 Issues 与 FAQ 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)
Environment (环境信息)
- Server Version: latest master
- Backend: any
- OS: CentOS 7.8 (reported), affects any OS with lsof
Expected & Actual behavior (期望与实际表现)
Starting hugegraph-server produces the following error:
lsof: unacceptable port specification in: -i : Starting HugeGraphServer in daemon mode...
Root cause: check_port() in util.sh extracts the port using:
local port=$(echo "$1" | awk -F':' '{print $3}')
This assumes a 3-part URL like http://host:port. Since #2944 removed the http:// prefix from the default config, restserver.url now defaults to 127.0.0.1:8080 (no scheme). Splitting on : gives only 2 fields, so $3 is empty and lsof -i : is called with no port.
Note: check_port accidentally works for gremlin because its fallback hardcodes http://127.0.0.1:8182 — only the REST URL is broken.
The same broken check_port exists in all three util.sh files:
- hugegraph-server/.../bin/util.sh line 84
- hugegraph-pd/.../bin/util.sh line 86
- hugegraph-store/.../bin/util.sh line 85
Though only hugegraph-server actively calls it.
Fix: replace the awk expression with:
local port=$(echo "$1" | sed 's|.:||' | sed 's|/.||')
This correctly handles all URL formats:
- 127.0.0.1:8080 → 8080 ✓
- http://127.0.0.1:8080 → 8080 ✓
- http://127.0.0.1:8080/ → 8080 ✓
- http://[::1]:8080 → 8080 ✓
Related: #2944 (changed default restserver.url format, exposing this bug) Reported in: #3001
Good bug report, @bitflicker64 — this is clearly the same issue @mywgl reported in #3001 [1], and your analysis and proposed fix look correct.
Confirming the current state: all three check_port functions still use the broken awk -F':' '{print $3}' extraction [2] [3] [4], and no fix has been merged yet. The bug was exposed by #2944, which allowed scheme-less URLs like 127.0.0.1:8080 as the default restserver.url [5].
Your proposed sed fix handles all the edge cases (trailing slash, IPv6, path suffixes) more robustly than the awk -F':' '{print $NF}' workaround @mywgl suggested in #3001. A PR with this fix across all three util.sh files would be welcome.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.