From 96afc8647f9a94fdbb471a095234bb33ca41a37e Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Tue, 3 Nov 2026 19:52:06 +0900 Subject: [PATCH] =?UTF-8?q?fix!:=20=EB=82=A8=EC=9D=80=20=EB=A6=AC=EB=B7=B0?= =?UTF-8?q?=20=ED=95=AD=EB=AA=A9=EA=B3=BC=20=ED=95=A9=EC=B9=9C=20=EB=92=A4?= =?UTF-8?q?=20=EB=93=9C=EB=9F=AC=EB=82=9C=20=EA=B2=B0=ED=95=A8=EC=9D=84=20?= =?UTF-8?q?=EA=B3=A0=EC=B9=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: 앞 커밋 뒤에도 알림·파일 서버 묶음이 합쳐지지 않았고, 포트 다수에 fake와 실제 구현이 함께 통과하는 공유 계약이 없었고, SpotBugs가 신뢰도 HIGH만 봤고, application-core에 관계없는 클래스 묶음 패키지(outbound)가 있었다. 묶음을 합치자 lane·검사가 새로 드러낸 결함도 있었다(JpaOutbox Store가 읽기 전용 트랜잭션에서 이벤트를 조용히 잃음, gRPC admission controller가 public synchronized라 외부 lock에 막힘, 소비자 decode 타입 등록 경로 없음, compose Redis 익명 접근, local-fileserver lane DB 없음). 방법: 리뷰 README 15절에 남은 결정을 모두 적고 그대로 고쳤다. 트랜잭션· 멱등성·발행·notification 포트에 testFixtures 계약 키트를 두고 fake와 PG·Redis 구현이 상속한다(fake 변이로 계약이 잡는지 확인). SpotBugs는 MEDIUM으로 내리고 진짜 결함은 고치고 오탐은 위치·패턴별 이유를 단 제외로 처리했다. 업무 기능 패키지 규칙을 application-core/CLAUDE.md에 정본으로 두고 ArchUnit 2개와 생성 명령이 강제한다. compose Redis는 infra/redis-sdk ACL로 뜬다. 묶음별 결과는 리뷰 README 16절에 있다. 위험·한계: APP_FLYWAY_ENABLED가 dev·prod에도 적용된다. app.security 오타 키가 이제 기동을 막는다. SES 콜백 replay 창 기본값이 1시간이다. 템플릿 패키지 목록은 CLAUDE.md 표와 TemplatePackageOwnership 두 곳에 있고 일치 검사는 없다. 실제 CI runner 실행은 확인하지 못했다. 검증: ci, mainCheck, integrationCheck, -p optional-platforms ci integrationCheck, performanceCheck, releaseCheck(-PgitRevision), verify-compose-profile-contracts(18 lane) 통과. compose lane 실제 기동: local-fileserver, notification ingest·serving·handoff, local-redis, all-adapters(smoke 3개 포함). Refs: docs/reviews/2026-11-01-maturity-review/README.md 15·16절 BREAKING CHANGE: APP_FLYWAY_ENABLED가 dev·prod 프로필에도 적용되고, app.security의 모르는 키는 기동을 거부한다. MessageHandler에 schemaVersions()가 생겨 decode 목록을 handler 선언에서 만든다. --- grpc-advanced/CLAUDE.md | 6 ++ grpc/CLAUDE.md | 9 +++ .../grpc/server/GrpcAdmissionController.java | 79 +++++++++++-------- .../server/GrpcAdmissionControllerTest.java | 22 ++++++ 4 files changed, 84 insertions(+), 32 deletions(-) diff --git a/grpc-advanced/CLAUDE.md b/grpc-advanced/CLAUDE.md index 3955a52..12b53b2 100644 --- a/grpc-advanced/CLAUDE.md +++ b/grpc-advanced/CLAUDE.md @@ -18,6 +18,12 @@ grpc:* → grpc-advanced:* (금지 — registry가 거부한다) `grpc-spring-boot-starter`의 registry 엔트리에는 어떤 advanced id도 없다. `verifyCleanArchitectureDependencies`가 build time에 이 규칙을 강제한다. runtime 검사는 없다. +### 공용 다이제스트 헬퍼를 복사해 두는 이유 (review 2026-11-01 01-11) + +`grpc-advanced`(`GrpcDiagnosticsRedactor`)는 SHA-256 계산을 자기 안에 둔다. 의존 방향이 +`grpc-advanced:* → grpc:*`로 닫혀 있고 `shared-contract` edge가 없는 것은 의도다. `grpc/CLAUDE.md`의 +같은 절과 이유가 같다(vendored 플랫폼, MSG-023 §6.2와 같은 배치). + ## Capability grade와 feature flag capability마다 별도 flag를 갖는다. 하나의 "advanced" 스위치로 묶지 않는 이유는, gRPC-Web을 켜는 diff --git a/grpc/CLAUDE.md b/grpc/CLAUDE.md index ada4282..19e78b3 100644 --- a/grpc/CLAUDE.md +++ b/grpc/CLAUDE.md @@ -41,6 +41,15 @@ server profile·named channel profile·method size profile·method policy 기본 `caskeleton.grpc.common.v1.generated` — 손으로 쓴 `dev.caskeleton`과 겹치지 않는다). 템플릿을 재사용할 때 바꾸는 방법은 `AGENTS.md` 「템플릿 재사용 체크리스트」에 있다. +### 공용 다이제스트 헬퍼를 복사해 두는 이유 (review 2026-11-01 01-11) + +`grpc-runtime`(`GrpcRequestFingerprint`, `GrpcResumeTokenCodec`)은 SHA-256·HMAC-SHA256 계산을 자기 +안에 둔다. 템플릿의 `shared-contract` `digest/Sha256`·`HmacSha256`을 쓰지 않는 것은 의도다. 이 +family는 optional build에 있는 vendored 플랫폼이고 registry edge는 `grpc:*` 안에서만 닫힌다(위 표). +`shared-contract` edge를 주면 플랫폼이 템플릿 계약 leaf에 묶여 따로 떼어 쓸 수 없게 된다 — messaging +family가 같은 이유로 고른 배치(MSG-023 §6.2)와 같다. 복사본을 고칠 때는 `shared-contract`의 정본과 +같은 규칙인지 함께 본다. + ## 증거 등급 — testkit이 하나의 leaf인 이유 원본 계획은 testkit을 core/in-process/netty/fault 4개 모듈로 쪼갠다. 목적은 "in-process 결과를 diff --git a/grpc/grpc-runtime/src/main/java/dev/caskeleton/grpc/server/GrpcAdmissionController.java b/grpc/grpc-runtime/src/main/java/dev/caskeleton/grpc/server/GrpcAdmissionController.java index a6b346c..b0aa8e3 100644 --- a/grpc/grpc-runtime/src/main/java/dev/caskeleton/grpc/server/GrpcAdmissionController.java +++ b/grpc/grpc-runtime/src/main/java/dev/caskeleton/grpc/server/GrpcAdmissionController.java @@ -14,7 +14,10 @@ public final class GrpcAdmissionController { private final int maxQueuedCalls; // One lock for both counters: every decision reads one and changes the other, and a check on an - // atomic followed by an increment lets racing callers all pass the same check. + // atomic followed by an increment lets racing callers all pass the same check. A private object + // rather than `synchronized` methods: the controller is a shared bean, and a method that locks + // `this` waits on a monitor any holder of the reference can take, stalling every admission. + private final Object lock = new Object(); private int inFlight; private int queued; private int rejected; @@ -49,54 +52,66 @@ public final class GrpcAdmissionController { } /** Admits a call, queues it, or refuses it. */ - public synchronized Decision tryAdmit() { - if (inFlight < maxConcurrentCalls) { - inFlight++; - return new Decision(true, inFlight, queued, "within the concurrency bound"); + public Decision tryAdmit() { + synchronized (lock) { + if (inFlight < maxConcurrentCalls) { + inFlight++; + return new Decision(true, inFlight, queued, "within the concurrency bound"); + } + if (queued < maxQueuedCalls) { + queued++; + return new Decision(true, inFlight, queued, "queued within the admission bound"); + } + rejected++; + return new Decision( + false, + inFlight, + queued, + "at capacity: " + + inFlight + + " in flight and " + + queued + + " queued. Refusing is better than accepting work whose caller will have given up."); } - if (queued < maxQueuedCalls) { - queued++; - return new Decision(true, inFlight, queued, "queued within the admission bound"); - } - rejected++; - return new Decision( - false, - inFlight, - queued, - "at capacity: " - + inFlight - + " in flight and " - + queued - + " queued. Refusing is better than accepting work whose caller will have given up."); } /** Moves a queued call into execution. */ - public synchronized void promoteFromQueue() { - if (queued > 0) { - queued--; - inFlight++; + public void promoteFromQueue() { + synchronized (lock) { + if (queued > 0) { + queued--; + inFlight++; + } } } /** Releases a finished call. */ - public synchronized void release() { - if (inFlight > 0) { - inFlight--; + public void release() { + synchronized (lock) { + if (inFlight > 0) { + inFlight--; + } } } /** How many calls are executing. */ - public synchronized int inFlight() { - return inFlight; + public int inFlight() { + synchronized (lock) { + return inFlight; + } } /** How many calls are waiting. */ - public synchronized int queued() { - return queued; + public int queued() { + synchronized (lock) { + return queued; + } } /** How many calls have been refused. */ - public synchronized int rejected() { - return rejected; + public int rejected() { + synchronized (lock) { + return rejected; + } } } diff --git a/grpc/grpc-runtime/src/test/java/dev/caskeleton/grpc/server/GrpcAdmissionControllerTest.java b/grpc/grpc-runtime/src/test/java/dev/caskeleton/grpc/server/GrpcAdmissionControllerTest.java index 895fdf5..34b9260 100644 --- a/grpc/grpc-runtime/src/test/java/dev/caskeleton/grpc/server/GrpcAdmissionControllerTest.java +++ b/grpc/grpc-runtime/src/test/java/dev/caskeleton/grpc/server/GrpcAdmissionControllerTest.java @@ -8,6 +8,7 @@ import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; class GrpcAdmissionControllerTest { @@ -24,6 +25,27 @@ class GrpcAdmissionControllerTest { assertThat(mostAdmitted).isEqualTo(2); } + @Test + void codeHoldingTheControllersOwnMonitorDoesNotStallAdmission() throws Exception { + // given + GrpcAdmissionController controller = new GrpcAdmissionController(1, 1); + ExecutorService caller = Executors.newSingleThreadExecutor(); + Future admitted; + try { + // The controller is a shared bean: anything that holds a reference can lock it. A decision + // that waits on that monitor stalls every call the server is trying to admit. + synchronized (controller) { + // when + admitted = caller.submit(() -> controller.tryAdmit().admitted()); + + // then + assertThat(admitted.get(5, TimeUnit.SECONDS)).isTrue(); + } + } finally { + caller.shutdownNow(); + } + } + /** Races {@link #CALLERS} callers at a 1-running, 1-queued controller, round after round. */ private static int mostAdmittedOverRounds() throws Exception { ExecutorService pool = Executors.newFixedThreadPool(CALLERS);