bitflicker64 commented on code in PR #3105:
URL: https://github.com/apache/hugegraph/pull/3105#discussion_r3650067959


##########
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:
   Resolved: curl download path now uses curl -fL with basename output.



##########
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:
   Resolved: ss/netstat probes now check actual kernel socket table, not 
limited to loopback.



##########
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:
   Resolved: /dev/tcp now has timeout 1 (when available) or run_with_deadline() 
with 2s watchdog.



##########
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:
   Resolved: uses : (null command) for /dev/tcp probe — no payload sent to 
services.



-- 
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]

Reply via email to