imbajin commented on code in PR #3105:
URL: https://github.com/apache/hugegraph/pull/3105#discussion_r3637856705
##########
hugegraph-pd/hg-pd-dist/src/assembly/static/bin/util.sh:
##########
@@ -20,10 +20,10 @@
# TODO: consider reuse it with server-dist module (almost same as it)
function command_available() {
local cmd=$1
- if [ $(command -v $cmd >/dev/null 2>&1) ]; then
- return 1
- else
+ if [[ -x "$(command -v "$cmd")" ]]; then
Review Comment:
⚠️ Correcting `command_available` makes the curl-only `download()` branch
reachable, but that branch still uses `-o ${path}/${link_url}`. Its callers
pass a full `https://.../opentelemetry-javaagent.jar` URL, so curl tries to
write through nonexistent nested `https:/...` directories and telemetry startup
still fails when wget is absent; the Store copy has the same behavior. Please
fix both helpers to use a basename destination such as `curl -L "$link_url" -o
"$path/$(basename "$link_url")"` and cover the curl-only path.
##########
hugegraph-server/hugegraph-dist/src/assembly/static/bin/util.sh:
##########
@@ -79,15 +79,36 @@ function process_id() {
return "$pid"
}
-# check the port of rest server is occupied
+# check whether the REST server port is occupied
function check_port() {
- local port=$(echo "$1" | sed 's|.*:||' | sed 's|/.*||')
- if ! command_available "lsof"; then
- echo "Required lsof but it is unavailable"
- exit 1
+ local url="$1"
+ local host
+ local port
+
+ # Extract port: last colon-delimited segment, strip trailing path
+ port=$(echo "$url" | sed 's|.*:||' | sed 's|/.*||')
+ if [[ -z "$port" ]]; then
+ return 0
fi
- lsof -i :"$port" >/dev/null
- if [ $? -eq 0 ]; then
+
+ # Extract host: handle IPv6 bracket notation e.g. http://[::1]:8080
+ if [[ "$url" =~ ://\[([^\]]*)\] ]]; then
+ host="${BASH_REMATCH[1]}"
+ else
+ host=$(echo "$url" | sed 's|.*://||' | sed 's|:.*||')
+ fi
+
+ # Wildcard binds include loopback: normalize to loopback for the probe
+ if [[ -z "$host" || "$host" == "0.0.0.0" ]]; then
+ host="127.0.0.1"
+ elif [[ "$host" == "::" ]]; then
+ host="::1"
+ fi
+
+ # Use bash /dev/tcp instead of lsof to avoid the FD-table walk that lsof
+ # performs under inflated nofile limits (e.g. kind / some Kubernetes
runtimes),
+ # which pegs CPU and prevents Java from starting.
+ if (echo >/dev/tcp/"$host"/"$port") >/dev/null 2>&1; then
Review Comment:
⚠️ Bash `/dev/tcp` has no deadline here. For a configured local/Pod address
whose firewall or CNI drops SYN packets, this check waits for the kernel retry
timeout and can still stall startup—the failure mode this change is intended to
remove. Please use a probe with an explicit short timeout or inspect listening
sockets without initiating a network connection, and cover the timeout path.
##########
hugegraph-server/hugegraph-dist/src/assembly/static/bin/util.sh:
##########
@@ -79,15 +79,36 @@ function process_id() {
return "$pid"
}
-# check the port of rest server is occupied
+# check whether the REST server port is occupied
function check_port() {
- local port=$(echo "$1" | sed 's|.*:||' | sed 's|/.*||')
- if ! command_available "lsof"; then
- echo "Required lsof but it is unavailable"
- exit 1
+ local url="$1"
+ local host
+ local port
+
+ # Extract port: last colon-delimited segment, strip trailing path
+ port=$(echo "$url" | sed 's|.*:||' | sed 's|/.*||')
+ if [[ -z "$port" ]]; then
+ return 0
fi
- lsof -i :"$port" >/dev/null
- if [ $? -eq 0 ]; then
+
+ # Extract host: handle IPv6 bracket notation e.g. http://[::1]:8080
+ if [[ "$url" =~ ://\[([^\]]*)\] ]]; then
+ host="${BASH_REMATCH[1]}"
+ else
+ host=$(echo "$url" | sed 's|.*://||' | sed 's|:.*||')
+ fi
+
+ # Wildcard binds include loopback: normalize to loopback for the probe
+ if [[ -z "$host" || "$host" == "0.0.0.0" ]]; then
Review Comment:
⚠️ Mapping `0.0.0.0` to `127.0.0.1` only probes loopback. A process
listening on another local interface can make the loopback connect fail while
the subsequent wildcard Java bind still fails with `EADDRINUSE`; the `::` to
`::1` path has the same multi-interface gap. Please make wildcard checks cover
the actual bind scope (for example through the kernel listening table or all
local addresses) and add IPv4/IPv6 regressions with a non-loopback listener.
##########
hugegraph-server/hugegraph-dist/src/assembly/static/bin/util.sh:
##########
@@ -79,15 +79,36 @@ function process_id() {
return "$pid"
}
-# check the port of rest server is occupied
+# check whether the REST server port is occupied
function check_port() {
- local port=$(echo "$1" | sed 's|.*:||' | sed 's|/.*||')
- if ! command_available "lsof"; then
- echo "Required lsof but it is unavailable"
- exit 1
+ local url="$1"
+ local host
+ local port
+
+ # Extract port: last colon-delimited segment, strip trailing path
+ port=$(echo "$url" | sed 's|.*:||' | sed 's|/.*||')
+ if [[ -z "$port" ]]; then
+ return 0
fi
- lsof -i :"$port" >/dev/null
- if [ $? -eq 0 ]; then
+
+ # Extract host: handle IPv6 bracket notation e.g. http://[::1]:8080
+ if [[ "$url" =~ ://\[([^\]]*)\] ]]; then
+ host="${BASH_REMATCH[1]}"
+ else
+ host=$(echo "$url" | sed 's|.*://||' | sed 's|:.*||')
+ fi
+
+ # Wildcard binds include loopback: normalize to loopback for the probe
+ if [[ -z "$host" || "$host" == "0.0.0.0" ]]; then
+ host="127.0.0.1"
+ elif [[ "$host" == "::" ]]; then
+ host="::1"
+ fi
+
+ # Use bash /dev/tcp instead of lsof to avoid the FD-table walk that lsof
+ # performs under inflated nofile limits (e.g. kind / some Kubernetes
runtimes),
+ # which pegs CPU and prevents Java from starting.
+ if (echo >/dev/tcp/"$host"/"$port") >/dev/null 2>&1; then
Review Comment:
🧹 `echo` writes a newline to whichever service already owns the port,
although detecting a listener only requires opening the connection. This can
create parse errors, logs, or error metrics in the existing REST/Gremlin
service. Please open and close the descriptor without payload, for example with
`: >/dev/tcp/"$host"/"$port"`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]