imbajin commented on code in PR #2945:
URL: https://github.com/apache/hugegraph/pull/2945#discussion_r4303634961


##########
hugegraph-server/hugegraph-dist/src/assembly/static/bin/arthas.sh:
##########
@@ -0,0 +1,201 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Offline attachment to a running Server or Store using the bundled agent.
+set -euo pipefail
+
+fail() { echo "Error: $*" >&2; exit 1; }
+usage() {
+    echo "Usage: $0 [--pid PID] [--telnet-port PORT] [--target-ip ADDRESS] 
[--command COMMAND]"
+    echo "          [--username USER] [--password PASSWORD]"
+    echo "Run as the service OS user; defaults to bin/pid and loopback port 
3658."
+    echo "New agents disable HTTP/MCP; use the existing telnet port for an 
active agent."
+    echo "Exiting this helper stops Arthas, including after --command or quit; 
the JVM keeps running."
+}
+
+BIN=$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+TOP=$(cd -P "$BIN/.." && pwd)
+pid=""
+port=3658
+target_ip=127.0.0.1
+username=""
+password=""
+command=""
+boot_args=()
+while [ "$#" -gt 0 ]; do
+    case "$1" in
+        --pid|--telnet-port|--target-ip|--command|--username|--password)
+            [ "$#" -ge 2 ] || fail "Missing value for $1"
+            case "$1" in
+                --pid) pid=$2 ;;
+                --telnet-port) port=$2 ;;
+                --target-ip) target_ip=$2 ;;
+                --command) command=$2 ;;
+                --username) username=$2 ;;
+                --password) password=$2 ;;
+            esac
+            shift 2 ;;
+        -h|--help) usage; exit 0 ;;
+        *) usage >&2; fail "Unknown option: $1" ;;
+    esac
+done
+# Native batch files contain one command per line.
+for credential in "$username" "$password"; do
+    [[ "$credential" != *$'\n'* && "$credential" != *$'\r'* ]] || fail 
"Credentials must be single-line values"
+done
+if [ -z "$pid" ]; then
+    [ -r "$BIN/pid" ] || fail "No bin/pid; start the service or supply --pid 
PID"
+    pid=$(cat "$BIN/pid")
+fi
+[[ "$pid" =~ ^[1-9][0-9]{0,9}$ ]] || fail "PID must be a positive integer"
+[[ "$port" =~ ^[1-9][0-9]{0,4}$ ]] && [ "$port" -le 65535 ] || fail "Invalid 
telnet port"
+[ -t 0 ] || [ -n "$command" ] || fail "Interactive use needs a terminal; use 
--command COMMAND"
+case "$target_ip" in
+    [Ll][Oo][Cc][Aa][Ll][Hh][Oo][Ss][Tt]) target_ip=127.0.0.1 ;;
+esac
+JAVA=${JAVA_HOME:+$JAVA_HOME/bin/}java
+ARTHAS="$TOP/lib/arthas"
+[ -f "$ARTHAS/arthas-boot.jar" ] || fail "Bundled Arthas files are missing 
from lib/arthas"
+# Keep the listener within this diagnosis session. Verify its PID before 
stopping
+# it, since an occupied port must never stop a different application's agent.
+state_dir=$(mktemp -d)
+client_pid=""
+attaching=true
+connect_ip=$target_ip
+quote_argument() {
+    local value=${1//\'/\'\\\'\'}
+    printf "'%s'" "$value"
+}
+write_batch() {
+    local file=$1
+    local commands=$2
+    {
+        if [ -n "$password" ]; then
+            printf 'auth --username %s %s\n' "$(quote_argument 
"${username:-arthas}")" "$(quote_argument "$password")"
+        fi
+        # Match arthas-client --command's semicolon-separated command syntax.
+        printf '%s\n' "${commands//;/$'\n'}"
+    } > "$file"
+}
+redact_auth_echo() {
+    local line
+    while IFS= read -r line || [ -n "$line" ]; do
+        case "$line" in
+            *'$ auth --username '*) printf '%s$ auth [credentials omitted]\n' 
"${line%%'$ auth --username '*}" ;;
+            *) printf '%s\n' "$line" ;;
+        esac
+    done
+}
+# The native client's -t option does not bound its final response wait.
+bounded_client() {
+    write_batch "$state_dir/cleanup.commands" "$1"
+    "$JAVA" -jar "$ARTHAS/arthas-client.jar" -t 5000 -f 
"$state_dir/cleanup.commands" "$connect_ip" "$port" &

Review Comment:
   Fixed: cleanup now accepts exactly one complete native session JAVA_PID row. 
Authentication responses cannot supply that identity, and missing or duplicate 
rows fail closed. A real two-JVM regression reproduced the original mistaken 
shutdown; the revised helper leaves the other agent running and still cleans up 
the rightful owner when its username contains a misleading PID. Both 
application JVMs remain alive.



##########
hugegraph-server/hugegraph-dist/src/assembly/static/bin/ArthasAttach.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Pattern;
+
+import com.sun.tools.attach.VirtualMachine;
+import com.taobao.arthas.core.config.FeatureCodec;
+
+class ArthasAttach {
+    public static void main(String[] args) throws Exception {
+        String ip = args[5];
+        InetAddress address = InetAddress.getByName(ip);
+        String connectIp = address.isAnyLocalAddress() ?
+                           (address.getAddress().length == 4 ? "127.0.0.1" : 
"::1") : ip;

Review Comment:
   Fixed: both wildcard listeners now prefer 127.0.0.1 for helper connections 
and cleanup on the native dual-stack JVM. The regression now covers 0.0.0.0 and 
:: without explicit credentials, and the mapping is synchronized in the runtime 
and bilingual website guidance. Native Server, Store and Linux runs passed.



##########
hugegraph-server/hugegraph-dist/src/assembly/static/conf/rest-server.properties:
##########
@@ -12,10 +12,16 @@ batch.max_write_ratio=80
 batch.max_write_threads=0
 
 # configuration of arthas
+# Legacy aliases: arthas.telnetPort, arthas.httpPort, arthas.disabledCommands.
+# The snake_case key takes precedence when both forms are configured.
+# Different values for both forms produce a warning when the agent is 
activated.
 arthas.telnet_port=8562
 arthas.http_port=8561
+# Defaults to local access. External binding (e.g. 0.0.0.0) exposes diagnostic 
commands;
+# enable Arthas native authentication and restrict network access before 
exposing it.

Review Comment:
   Documented the supported native route: set -Darthas.username and 
-Darthas.password on the Server JVM, then restart before API activation. The 
template and runtime/bilingual documentation explain process-list exposure, 
generated wildcard passwords, and localConnectionNonAuth. A native fixture 
using the full API configuration map verified these JVM properties. Following 
the requested minimal native boundary, this remains configuration guidance 
rather than a new runtime password-inspection warning or REST credential 
setting.



##########
docs/server-runtime.md:
##########
@@ -79,11 +79,120 @@ existing precedence; see [container heap 
sizing](../docker/README.md#server-heap
 
 ### Arthas diagnostics
 
-Server bundles Arthas 4.1.5. Activate the agent with `PUT /arthas` using the 
Server's
-configured authentication. The existing `arthas.ip`, `arthas.httpPort`,
-`arthas.telnetPort` and `arthas.disabledCommands` options still configure the 
agent.
-HugeGraph disables the bundled agent's optional MCP endpoint and keeps the 
existing
-activation response and diagnostic HTTP/telnet interfaces.
+Server and Store bundle Arthas 4.1.5, managed by the root POM. PD does not 
embed
+an Arthas agent. Diagnostic ports bind to `127.0.0.1` by default. 
Administrators
+can explicitly configure another valid address, including `0.0.0.0` for all 
IPv4

Review Comment:
   Corrected the runtime and bilingual guidance: either wildcard may accept 
both IPv4 and IPv6 depending on OS/JVM settings, so network rules must cover 
both. Native Linux/JDK and Arthas fixtures confirmed dual-stack access. No 
additional binding restriction was introduced.



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