Files
document-haness/docs/clean-architecture-backend-template/tech-log-studio/state-ownership-and-concurrency/case/case-grpc-advanced-resilience-f03.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

102 lines
4.8 KiB
Markdown

---
kind: CASE
slug: grpc-advanced-resilience-f03
title: 리졸버의 개정 가드가 비교 후 교체가 아니다
topic: state-ownership-and-concurrency
project: clean-architecture-backend-template
status: 게시 전
sourceRevision: 21234e38cdb9a926cbc92bb97a2aee2e4a7d2916
rootTreeNode: case:grpc-advanced-resilience-f03
evidenceCapturedOn: 2026-09-01
assets:
- key: grpc-advanced-resilience-f03
file: ../../../final/evidence/rendered/grpc-advanced-resilience-f03.svg
- key: grpc-advanced-resilience-f03-diagram
file: ../../../final/assets/diagrams/grpc-advanced-resilience-f03.svg
evidence:
- ../../../final/evidence/raw/grpc-advanced-resilience-f03.txt
source:
- 원본 분석 절은 analysis/grpc/grpc-advanced-resilience.md#L176 이다.
module: grpc-advanced-resilience
priority: P2
---
# 리졸버의 개정 가드가 비교 후 교체가 아니다
GrpcCustomResolver 의 javadoc 이 지키겠다고 하는 것은 명확하다. 빈 집합은 GrpcEndpointSnapshot 의 생성자가 지키므로 성립한다.
## 문제
GrpcCustomResolver 의 javadoc 이 지키겠다고 하는 것은 명확하다.
빈 집합은 GrpcEndpointSnapshot 의 생성자가 지키므로 성립한다.
## 결론
개정 가드는 그렇지 않다.
AtomicReference 를 쓰면서 읽기와 쓰기 사이에 원자성이 없다.
개정 5 와 6 을 든 두 스레드가 같은 applied(개정 4)를 읽으면 둘 다 supersedes 를 통과하고, 나중에 set 하는 쪽이 이긴다.
6 이 먼저 쓰이고 5 가 덮으면 채널이 옛 엔드포인트로 되돌아간다 — 개정 번호가 존재하는 이유가 정확히 그것을 막는 것이다.
listener.accept(update) 도 set 밖에 있으므로, applied 의 최종 값이 옳더라도 리스너(=채널)가 받는 순서는 뒤집힐 수 있다.
채널은 마지막으로 받은 것을 믿는다.
같은 형태가 이 가족에 셋이다.
정본이 같은 리프 안에 있다는 점이 §12.2 의 대조와 같다 — 이 리프는 예산에서는 CAS 를 쓰고 리졸버에서는 쓰지 않는다.
## 검증 환경
OpenJDK : 21.0.12 java -version 으로 확인
Gradle : 9.0.0 src/gradle/wrapper/gradle-wrapper.properties 의 distributionUrl 로 확인
확인 방식 : GrpcCustomResolver 참조 5건 검색과 개정 가드의 읽기·쓰기 순서 확인
소스 수정 : x
## 재현 조건
원문은 analysis/grpc/grpc-advanced-resilience.md#L176 에 있다.
## 본문
<!-- body:start -->
`GrpcCustomResolver` 의 javadoc 이 지키겠다고 하는 것은 명확하다. 빈 집합은 `GrpcEndpointSnapshot` 의 생성자가 지키므로 성립한다. 개정 가드는 그렇지 않다.
## 가드가 지키지 못하는 구간
:::evidence key="grpc-advanced-resilience-f03-diagram" alt="두 스레드의 개정이 같은 applied 읽기와 둘 다 통과를 지나 옛 엔드포인트 회귀로 이어진다" caption="가드가 지키지 못하는 구간" zoom="false"
:::
`AtomicReference` 를 쓰면서 읽기와 쓰기 사이에 원자성이 없다. 개정 5 와 6 을 든 두 스레드가 같은 `applied`(개정 4)를 읽으면 둘 다 `supersedes` 를 통과하고, 나중에 `set` 하는 쪽이 이긴다. 6 이 먼저 쓰이고 5 가 덮으면 **채널이 옛 엔드포인트로 되돌아간다** — 개정 번호가 존재하는 이유가 정확히 그것을 막는 것이다.
## GrpcCustomResolver 참조 위치
:::evidence key="grpc-advanced-resilience-f03" alt="코드베이스에서 GrpcCustomResolver 를 검색한 출력 5줄. 이 기록이 세는 참조가 그 출력에 그대로 보인다." caption="GrpcCustomResolver 코드베이스 검색 — 5줄 · exit 0" zoom="true"
:::
## 통지 순서도 뒤집힐 수 있다
`listener.accept(update)``set` 밖에 있으므로, `applied` 의 최종 값이 옳더라도 리스너(=채널)가 받는 순서는 뒤집힐 수 있다. 채널은 마지막으로 받은 것을 믿는다.
## 정본이 같은 리프 안에 있다
이 리프는 예산에서는 CAS 를 쓰고 리졸버에서는 쓰지 않는다. 같은 형태가 이 가족에 셋이다.
## 테스트는 순차 경로만 본다
`a stale revision is dropped rather than applied` 는 단일 스레드에서 개정 2 를 적용한 뒤 개정 1 을 제시한다. 순차적으로는 가드가 정확히 작동한다.
## 수정
`applied.updateAndGet` 안에서 판정과 교체를 함께 하거나, `compareAndSet(observed, snapshot)` 이 실패하면 다시 읽어 판정한다. 리스너 통지는 성공한 CAS 뒤에 그 CAS 가 이긴 순서로 해야 한다 — 예산 쪽의 `tryConsume` 루프가 같은 리프 안의 본보기다. 이 리프가 배선되지 않으므로 P2.
## 확인하지 못한 것
두 스레드로 개정을 겹쳐 옛 엔드포인트 회귀를 재현하지 않았다. 읽기와 쓰기가 원자적이지 않다는 코드 형태로 판정했다.
<!-- body:end -->