imbajin commented on code in PR #3258:
URL: https://github.com/apache/hugegraph/pull/3258#discussion_r4173366501
##########
hugegraph-server/hugegraph-dist/src/assembly/static/bin/hugegraph-server.sh:
##########
@@ -121,13 +121,43 @@ if [ "$JAVA_OPTIONS" = "" ]; then
echo "Failed to start HugeGraphServer, requires at least ${MIN_MEM}MB
free memory" >> "${OUTPUT}"
exit 1
fi
- JAVA_OPTIONS="-Xms${MIN_MEM}m -Xmx${XMX}m -XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=${LOGS} ${USER_OPTION}"
+ JAVA_OPTIONS="-Xms${MIN_MEM}m -Xmx${XMX}m ${USER_OPTION}"
# Rolling out detailed GC logs
#JAVA_OPTIONS="${JAVA_OPTIONS} -XX:+UseGCLogFileRotation
-XX:GCLogFileSize=10M -XX:NumberOfGCLogFiles=3 \
# -Xloggc:./logs/gc.log -XX:+PrintHeapAtGC
-XX:+PrintGCDetails -XX:+PrintGCDateStamps"
fi
+# Keep heap dumps and JVM crash logs in $LOGS whatever JAVA_OPTIONS holds.
They go
+# first so a value from JAVA_OPTIONS, -j or _JAVA_OPTIONS, all later on the
command
+# line, still wins. JAVA_TOOL_OPTIONS and JDK_JAVA_OPTIONS are read before the
command
+# line, so a flag set there is left out here instead of being overridden.
+# A restarted container often reuses the JVM's PID, and HotSpot will not
overwrite an
+# existing crash log or heap dump, so the file names also carry the launch
time. The
+# script execs java below, so $$ is the JVM's PID.
+LAUNCH_STAMP=$(date +%Y%m%d-%H%M%S)
+CRASH_OPTIONS=""
+SET_HEAP_DUMP="true"
+SET_HEAP_DUMP_PATH="true"
+SET_ERROR_FILE="true"
+for OPTION in ${JAVA_TOOL_OPTIONS:-} ${JDK_JAVA_OPTIONS:-}; do
+ case "${OPTION}" in
+ -XX:[+-]HeapDumpOnOutOfMemoryError) SET_HEAP_DUMP="false" ;;
+ -XX:HeapDumpPath=*) SET_HEAP_DUMP_PATH="false" ;;
+ -XX:ErrorFile=*) SET_ERROR_FILE="false" ;;
+ esac
+done
+if [[ $SET_HEAP_DUMP == "true" ]]; then
+ CRASH_OPTIONS="${CRASH_OPTIONS} -XX:+HeapDumpOnOutOfMemoryError"
+fi
+if [[ $SET_HEAP_DUMP_PATH == "true" ]]; then
+ CRASH_OPTIONS="${CRASH_OPTIONS}
-XX:HeapDumpPath=${LOGS}/java_pid$$_${LAUNCH_STAMP}.hprof"
Review Comment:
⚠️ Blocking: no. Summary: This stamp has one-second precision, and the
heap-dump filename also uses `$$`; a rapid restart in the same container can
reuse PID 1 within that second and target the same HPROF path. Please add a
per-launch unique suffix or finer timestamp so each startup can retain its own
dump. Evidence: `LAUNCH_STAMP` at line 138 and this path at line 154; [OpenJDK
11 defaults `HeapDumper.dump(..., overwrite)` to
`false`](https://github.com/openjdk/jdk11u/blob/master/src/hotspot/share/services/heapDumper.hpp#L73).
--
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]