Files
document-haness/docs/clean-architecture-backend-template/tech-log-studio/security-policy-enforcement/case/case-grpc-server-f04.md
T
DongHyeonkaandClaude Opus 5 b2963105a8 docs(keycloak-session-store): import the session-storage lab as a new project
The keycloak project ended with four open questions that design could not
settle. A two-VM lab was built to answer them by measurement, and this is
that material: 26 experiments, 125 raw command outputs, 22 browser captures.

Follows the import procedure in README.md.

  source/     the originating repository verbatim — 78 documents, 28 SVGs,
              8 manifests, plus .source-revision recording the commit
  final/      the SSOT
    document.md   729 lines written from the 29 experiment documents, not
                  concatenated: what was predicted, what was measured, and
                  where the measurement itself was wrong
    evidence/raw    125 outputs, flattened to <experiment>__<file> because
                    the originals collided (01-baseline.txt appeared three
                    times) and the audit only globs the top level
    evidence/meta   one per raw file; command and exitCode are null and the
                    README says why rather than inventing them
    evidence/browser  22 captures
    assets/       three diagrams through techviz
    .techviz/     their VizSpecs

A separate project rather than an addition to keycloak: the B-layer answers
that project's four questions, but the A, C and D layers are about cluster
failure, SSO and operations, and one document.md should hold one subject.
The four question records there can point here through 관계.

Recorded rather than papered over: only three of the 28 diagrams were
remade. The repository forbids hand-drawn SVG and forbids titles inside the
canvas; all 28 originals carry both, so converting them is redrawing, not
reformatting. They stay in source/ and the gap is written into the document.

verify-pipeline.py passes. audit-records.py reports no issues.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:51:59 +09:00

112 lines
5.2 KiB
Markdown

---
kind: CASE
slug: grpc-server-f04
title: 승인 제어기의 세 메서드가 원자적이지 않고, 큐 계수기를 되돌리는 경로가 없다
topic: security-policy-enforcement
project: clean-architecture-backend-template
status: 게시 전
sourceRevision: 21234e38cdb9a926cbc92bb97a2aee2e4a7d2916
rootTreeNode: case:grpc-server-f04
evidenceCapturedOn: 2026-09-01
assets:
- key: grpc-server-f04
file: ../../../final/evidence/rendered/grpc-server-f04.svg
- key: grpc-server-f04-diagram
file: ../../../final/assets/diagrams/grpc-server-f04.svg
evidence:
- ../../../final/evidence/raw/grpc-server-f04.txt
source:
- 원본 분석 절은 analysis/grpc/grpc-server.md#L211 이다.
module: grpc-server
priority: P2
---
# 승인 제어기의 세 메서드가 원자적이지 않고, 큐 계수기를 되돌리는 경로가 없다
이 리프가 SSOT 이므로 여기에 적는다. grpc-policy §17.1 이 이 클래스를 대조군으로 지목하는데, 지목된 쪽 문서에 판정이 없었다.
## 문제
이 리프가 SSOT 이므로 여기에 적는다.
grpc-policy §17.1 이 이 클래스를 대조군으로 지목하는데, 지목된 쪽 문서에 판정이 없었다.
## 결론
첫째, 읽고 나서 따로 증가시킨다.
경계에 있는 N 개 스레드가 모두 통과한다.
AtomicInteger 를 쓰면서 비교와 증가를 나눈 형태이고, 같은 가족의 정본이 GrpcRetryBudget.tryConsume 의 비교 후 교체 루프다.
release()·promoteFromQueue() 도 같다 — get() > 0 을 확인한 뒤 별도로 감소시키므로, 두 스레드가 같은 마지막 하나를 보고 둘 다 감소시켜 음수가 될 수 있다.
클래스가 Math.max(0, …) 같은 하한도 두지 않는다.
둘째, 큐 계수기를 되돌리는 경로가 없다.
큐에 들어간 호출도 admitted=true 를 받는다.
그런데 그 경로는 queued 만 올리고 inFlight 는 올리지 않는다.
## 검증 환경
OpenJDK : 21.0.12 java -version 으로 확인
Gradle : 9.0.0 src/gradle/wrapper/gradle-wrapper.properties 의 distributionUrl 로 확인
확인 방식 : 두 계수기의 증가·감소 지점 대조와 큐 계수기 반납 메서드 유무 확인
소스 수정 : x
## 재현 조건
원문은 analysis/grpc/grpc-server.md#L211 에 있다.
## 본문
<!-- body:start -->
이 리프가 SSOT 이므로 여기에 적는다. `grpc-policy` §17.1 이 이 클래스를 대조군으로 지목하는데, 지목된 쪽 문서에 판정이 없었다.
## 첫째 — 읽고 나서 따로 증가시킨다
```java
public Decision tryAdmit() {
int running = inFlight.get();
if (running < maxConcurrentCalls) {
inFlight.incrementAndGet(); // ← 읽기와 증가 사이에 다른 스레드가 들어온다
return new Decision(true, );
}
int waiting = queued.get();
if (waiting < maxQueuedCalls) {
queued.incrementAndGet(); // ← 같은 형태
```
경계에 있는 N 개 스레드가 모두 통과한다. 같은 가족의 정본이 `GrpcRetryBudget.tryConsume` 의 비교 후 교체 루프다. `release()`·`promoteFromQueue()` 도 같다 — `get() > 0` 을 확인한 뒤 별도로 감소시키므로 두 스레드가 같은 마지막 하나를 보고 둘 다 감소시켜 음수가 될 수 있고, `Math.max(0, …)` 같은 하한도 없다.
## 계수기 쌍의 비대칭
:::evidence key="grpc-server-f04-diagram" alt="진행 계수기 쪽에 tryAdmit 증가와 release 감소가 놓이고 큐 계수기 쪽에 tryAdmit 증가와 반납 메서드 없음이 놓인다" caption="계수기 쌍의 비대칭" zoom="false"
:::
## 대조군으로 지목된 클래스
:::evidence key="grpc-server-f04" alt="분석 문서 analysis/grpc/grpc-server.md 에서 이 기록의 근거 절을 그대로 잘라낸 15줄. 코드베이스를 측정한 것이 아니라 원본 판정이 무엇을 적었는지를 보여 준다." caption="analysis/grpc/grpc-server.md 발췌 — 15줄" zoom="true"
:::
## 둘째 — 큐 계수기를 되돌리는 경로가 없다
큐에 들어간 호출도 `admitted=true` 를 받는데 그 경로는 `queued` 만 올리고 `inFlight` 는 올리지 않는다. 그리고 끝난 호출을 반납하는 메서드는 하나뿐이다. 따라서 호출자가 `promoteFromQueue()` 를 정확히 한 번 끼워 넣지 않으면 계수기가 어긋난다 — 큐에서 실행된 호출이 끝나면 `queued` 는 그대로이고 `inFlight` 만 줄어든다. `releaseQueued()` 같은 메서드도, 그 짝짓기를 요구하는 서술도 없다.
## 시험이 짝지어 부른다
두 시험 모두 단일 스레드이고, `releaseAndPromotionTrackCapacity``release()``promoteFromQueue()` 를 짝지어 부른다. 짝짓지 않는 경로는 시험되지 않는다.
## 배선하는 순간 P1 이다
오늘 호출자가 없으므로(§12.1) P2. 승인 단계를 배선하면 부하 아래에서 경계가 새는 것과, 큐 계수기가 단조 증가해 `at capacity` 가 영구히 참이 되는 것이 함께 온다. 세 메서드를 비교 후 교체 루프로 바꾸고, 큐 경로에 대응하는 반납 메서드를 둔다.
## 확인하지 못한 것
경합을 실행으로 재현하지 않았다. 읽기와 증가가 분리되어 있다는 것과 하한 가드가 없다는 것으로 판정했다.
<!-- body:end -->