fix(compose): heap dump 경로를 컨테이너 메모리 한계 안의 tmpfs에 두지 않는다

문제: 기본 compose.yaml은 -XX:HeapDumpPath=/var/tmp/heap을 512m tmpfs로
붙였다. 컨테이너는 mem_limit 512m·swap 없음이고 힙은 그 75%(384m)다.
tmpfs에 쓴 페이지는 같은 컨테이너 메모리 한계에 잡힌다. 그래서
OutOfMemoryError 때 덤프를 쓰는 동안 컨테이너가 OOM kill(137)될 수 있었고,
runbook이 기대하는 깨끗한 끝(코드 3, ExitOnOutOfMemoryError)이 사라졌다.
덤프가 끝까지 써져도 tmpfs는 컨테이너가 끝나면 함께 사라져 읽을 수 없었다.
Dockerfile 주석은 오케스트레이터에 그 경로를 tmpfs로 붙이라고 했고,
internal-error-spike runbook은 없는 파일 이름(heapdump-<pid>.hprof)을 적었다.

고른 방법:
- 기본 compose.yaml은 그 경로에 아무것도 붙이지 않는다. 루트가 읽기
  전용이라 JVM은 파일을 만들지 못하고 바로 코드 3으로 끝난다. 덤프를 남기는
  dev lane(named volume heap-dumps)은 그대로다.
- scripts/verify-compose-profile-contracts.sh(prCheck의
  verifyComposeProfiles)가 모든 lane에서 그 경로의 tmpfs를 거절한다. 경로는
  Dockerfile의 -XX:HeapDumpPath에서 읽는다.
- Dockerfile 주석과 runbook 둘(runtime-jvm-oom 「진단」, internal-error-spike)에
  덤프를 남기는 법(Kubernetes emptyDir without medium: Memory·PV, dev lane
  volume)과 실제 파일 이름(java_pid<pid>.hprof)을 적었다.
- 버린 대안: 기본 compose에 named volume을 붙이기 — 기본 조립은 디스크에
  아무것도 남기지 않는다는 결정(compose.yaml 「No volume」 주석)과 다르다.
- 고치며 찾은 것(RR9-03-30): ComposeMergeCharacterizationTest는 어느 lane에서도
  돌지 않았다. integrationTest lane은 requires로 적은 클래스 넷만 고른다
  (StrictTestLanePlugin). 그 시험이 보던 기본·dev 조합 렌더링과 계약 스크립트는
  verifyComposeProfiles가 18개 lane으로 이미 본다. 시험과, 그 lane에 compose
  파일을 입력으로 선언하던 블록을 지웠다.

검증(desktop):
- RED: 기준 ca1fbfde + 검사 스크립트만으로 :verifyComposeProfiles 실패
  (기본 compose를 쓰는 lane마다 「heap dump path ... as a tmpfs」).
- 탐침(eclipse-temurin:21-jdk, 읽기 전용 루트, 메모리 192m·swap 없음,
  -Xmx96m으로 OutOfMemoryError):
  경로에 아무것도 없음 → "Unable to create /var/tmp/heap: Read-only file
  system", 코드 3. tmpfs → 덤프를 쓰다 코드 137(OOM kill). 디스크 마운트 →
  덤프 101MB가 남고 코드 3.
- GREEN: :verifyComposeProfiles(18 lane), :app-bootstrap:integrationTest,
  repositoryContractTest, spotlessCheck — 71건 실패 0, skip 1, rc=0.
This commit is contained in:
DongHyeonka
2026-11-13 03:55:38 +09:00
parent ca1fbfde79
commit 23139722e8
8 changed files with 50 additions and 151 deletions
+16 -3
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# The static half of the Compose contract: every lane renders, and renders exactly what it claims.
#
# Nine things are checked, and each exists because assuming it cost something:
# Ten things are checked, and each exists because assuming it cost something:
#
# 1. the Compose version, because `!override` is what stops the dev overlay's tmpfs merging with
# the base's and colliding with a bind mount, and it needs 2.24.4;
@@ -24,7 +24,11 @@
# would hide the same trade in production; the lane has to look like a deployment instead.
# 8. a lane's appMemoryLimit, when it has one, is a Compose memory size, because the smoke wrapper
# writes it into the application's mem_limit and a malformed one fails only at `up`.
# 9. the Keycloak realm artifact carries no key Keycloak refuses (below the lane loop).
# 9. the application's heap dump path (-XX:HeapDumpPath in the Dockerfile) is not a tmpfs, because a
# tmpfs is charged to the container's memory limit and is gone once the container exits: the
# dump written at an OutOfMemoryError could only push the container into an OOM kill and was
# never there to read (2026-11-12 review).
# 10. the Keycloak realm artifact carries no key Keycloak refuses (below the lane loop).
#
# Static only. Nothing starts here; scripts/run-compose-runtime-smoke.sh owns that.
set -euo pipefail
@@ -103,6 +107,8 @@ redis_authentication_problems() {
}
command -v jq >/dev/null 2>&1 || { echo "jq is required" >&2; exit 78; }
HEAP_DUMP_PATH="$(sed -n 's/.*-XX:HeapDumpPath=\([^ \\"]*\).*/\1/p' "${REPO_ROOT}/Dockerfile" | head -1)"
[[ -n "${HEAP_DUMP_PATH}" ]] || { echo "the Dockerfile sets no -XX:HeapDumpPath" >&2; exit 78; }
command -v docker >/dev/null 2>&1 || { echo "docker is required" >&2; exit 78; }
[[ -r "${CONTRACTS}" ]] || { echo "missing ${CONTRACTS}" >&2; exit 78; }
@@ -233,10 +239,17 @@ for index in $(seq 0 $((lane_count - 1))); do
fail "${id}: appMemoryLimit '${memory_limit}' is not a Compose memory size such as 1g"
fi
# 9. the heap dump path is not a tmpfs.
heap_tmpfs="$(jq -r --arg path "${HEAP_DUMP_PATH}" \
'.services.app.tmpfs // [] | .[] | split(":")[0] | select(. == $path)' <<<"${model}")"
if [[ -n "${heap_tmpfs}" ]]; then
fail "${id}: app mounts the heap dump path ${HEAP_DUMP_PATH} as a tmpfs, which counts against its memory limit and is gone when it exits"
fi
[[ ${FAILURES} -eq 0 ]] && echo "${id}: ${expected} @ ${runtime}"
done
# 9. the Keycloak realm artifact deserializes into Keycloak's own representation.
# 10. the Keycloak realm artifact deserializes into Keycloak's own representation.
#
# Keycloak rejects unknown fields rather than ignoring them, so one annotation key anywhere in the
# tree fails the whole import, the container exits 1, and every lane that needs an identity provider