Files
document-haness/docs/clean-architecture-backend-template/final/evidence/rendered/a11-f001-close-leak.svg
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

164 lines
14 KiB
XML

<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="1668" viewBox="0 0 1200 1668" role="img">
<title>terminal evidence</title>
<desc>Terminal-style rendering generated from retained command output. Sensitive-looking values are redacted in the visual asset.</desc>
<rect x="1" y="1" width="1198" height="1666" rx="14" fill="#0d1117" stroke="#30363d"/>
<rect x="1" y="1" width="1198" height="44" rx="14" fill="#161b22"/>
<rect x="1" y="30" width="1198" height="14" fill="#161b22"/>
<circle cx="24" cy="22" r="6" fill="#ff5f57"/>
<circle cx="44" cy="22" r="6" fill="#febc2e"/>
<circle cx="64" cy="22" r="6" fill="#28c840"/>
<text x="92" y="27" fill="#8b949e" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace">terminal evidence</text>
<text x="24" y="68" fill="#c9d1d9" font-size="15" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">$ set -e
D=$(mktemp -d); trap &#x27;rm -rf &quot;$D&quot;&#x27; EXIT
H=/shared/codebase/clean-architecture-backend-template/src/adapter/outb</tspan><tspan x="24" dy="22">ound/httpclient
JAR=$H/build/libs/httpclient-0.0.1+21234e38cdb9.jar
java -version 2&gt;&amp;1 | head -1
javac -encoding UTF-8 -</tspan><tspan x="24" dy="22">cp &quot;$JAR&quot; -d &quot;$D&quot; \
&quot;$H/src/testkit/java/dev/caskeleton/adapter/outbound/httpclient/testkit/ClientProfiles.java&quot;
cat &gt;</tspan><tspan x="24" dy="22"> &quot;$D/DrainThreadProbe.java&quot; &lt;&lt;&#x27;JAVA&#x27;
import dev.caskeleton.adapter.outbound.httpclient.profile.ClientRuntime;
import dev</tspan><tspan x="24" dy="22">.caskeleton.adapter.outbound.httpclient.profile.ClientRuntimeLease;
import dev.caskeleton.adapter.outbound.httpclient.pr</tspan><tspan x="24" dy="22">ofile.ClientRuntimeRegistry;
import dev.caskeleton.adapter.outbound.httpclient.profile.ClientRuntimeState;
import dev.ca</tspan><tspan x="24" dy="22">skeleton.adapter.outbound.httpclient.profile.RuntimeGeneration;
import dev.caskeleton.adapter.outbound.httpclient.testki</tspan><tspan x="24" dy="22">t.ClientProfiles;
import java.time.Duration;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
pu</tspan><tspan x="24" dy="22">blic final class DrainThreadProbe {
private static final String DRAIN = &quot;httpclient-runtime-drain&quot;;
private static</tspan><tspan x="24" dy="22"> ClientRuntime runtime(long generation, Runnable closer) {
return new ClientRuntime(
ClientProfiles.builder(</tspan><tspan x="24" dy="22">&quot;payment&quot;).build(), new RuntimeGeneration(generation), closer);
}
private static long drainThreads() {
return T</tspan><tspan x="24" dy="22">hread.getAllStackTraces().keySet().stream()
.filter(t -&gt; t.getName().startsWith(DRAIN))
.count();
}
</tspan><tspan x="24" dy="22"> private static String close(ClientRuntimeRegistry registry) {
try {
registry.close();
return &quot;정상 반환</tspan><tspan x="24" dy="22">&quot;;
} catch (RuntimeException failure) {
return failure.getClass().getSimpleName() + &quot;: &quot; + failure.getMessage(</tspan><tspan x="24" dy="22">);
}
}
/** The shape the resource-bound suite rotates in: no lease is held. */
private static void suiteShape</tspan><tspan x="24" dy="22">() {
System.out.println(&quot;[자원 경계 묶음이 도는 모양] 임차를 쥐지 않고 회전한다&quot;);
AtomicInteger closed = new At</tspan><tspan x="24" dy="22">omicInteger();
ClientRuntime first = runtime(1, closed::incrementAndGet);
long peak = 0;
try (ClientRuntimeR</tspan><tspan x="24" dy="22">egistry registry = new ClientRuntimeRegistry(Map.of(first.name(), first))) {
for (int generation = 2; generation &lt;</tspan><tspan x="24" dy="22">= 50; generation++) {
registry.swap(first.name(), runtime(generation, closed::incrementAndGet), Duration.ofSecon</tspan><tspan x="24" dy="22">ds(1));
peak = Math.max(peak, drainThreads());
}
}
System.out.println(&quot; 회전 49회 동안 관측된 dra</tspan><tspan x="24" dy="22">in 스레드 최대치 : &quot; + peak);
System.out.println(&quot; 닫힌 세대 : &quot; + closed.get() + &quot; / close() 후 drain 스레드 : &quot; +</tspan><tspan x="24" dy="22"> drainThreads());
System.out.println();
}
/** The path the record describes: one forceClose throws. */
privat</tspan><tspan x="24" dy="22">e static void refusingPool() {
System.out.println(&quot;[강제 닫기 하나가 던지는 경로]&quot;);
AtomicInteger released = ne</tspan><tspan x="24" dy="22">w AtomicInteger();
ClientRuntime first = runtime(1, () -&gt; {});
ClientRuntime second =
runtime(
</tspan><tspan x="24" dy="22"> 2,
() -&gt; {
released.incrementAndGet();
throw new IllegalStateException(&quot;pool </tspan><tspan x="24" dy="22">refused to close&quot;);
});
ClientRuntimeRegistry registry = new ClientRuntimeRegistry(Map.of(first.name(), </tspan><tspan x="24" dy="22">first));
ClientRuntimeLease lease = registry.acquire(first.name());
registry.swap(first.name(), second, Duration</tspan><tspan x="24" dy="22">.ofSeconds(30));
System.out.println(&quot; swap 직후 drain 스레드 : &quot; + drainThreads());
System.out.println(&quot; 1회차</tspan><tspan x="24" dy="22"> close() : &quot; + close(registry) + &quot; / drain 스레드 &quot; + drainThreads());
System.out.println(&quot; 거부한 런타임 state : &quot;</tspan><tspan x="24" dy="22"> + second.state()
+ &quot; / 자원 닫기 호출 &quot; + released.get() + &quot;&quot;);
second.forceClose();
System.out.print</tspan><tspan x="24" dy="22">ln(&quot; 다시 forceClose 후 자원 닫기 호출 : &quot; + released.get() + &quot;&quot;);
System.out.println(&quot; 2회차 close() : &quot; + clos</tspan><tspan x="24" dy="22">e(registry) + &quot; / drain 스레드 &quot; + drainThreads());
lease.close();
System.out.println();
}
/** No forceClos</tspan><tspan x="24" dy="22">e fails, yet the thread survives: the shutdown block throws on its own. */
private static void slowScheduler() throws </tspan><tspan x="24" dy="22">Exception {
System.out.println(&quot;[강제 닫기가 하나도 던지지 않는데 스레드가 남는 경로]&quot;);
ClientRuntime first =
</tspan><tspan x="24" dy="22"> runtime(
1,
() -&gt; {
long until = System.nanoTime() + Duration.ofSeconds(8).</tspan><tspan x="24" dy="22">toNanos();
while (System.nanoTime() &lt; until) {
try {
Thread.sleep(50);
</tspan><tspan x="24" dy="22"> } catch (InterruptedException ignored) {
// The pool&#x27;s own close ignores the interrupt,</tspan><tspan x="24" dy="22"> which shutdownNow can only send.
}
}
});
ClientRuntime second = runtime(2</tspan><tspan x="24" dy="22">, () -&gt; {});
ClientRuntimeRegistry registry = new ClientRuntimeRegistry(Map.of(first.name(), first));
ClientRunt</tspan><tspan x="24" dy="22">imeLease lease = registry.acquire(first.name());
registry.swap(first.name(), second, Duration.ofMillis(50));
Thr</tspan><tspan x="24" dy="22">ead.sleep(400);
System.out.println(&quot; 마감 작업이 도는 중 drain 스레드 : &quot; + drainThreads());
long started = Sys</tspan><tspan x="24" dy="22">tem.nanoTime();
String outcome = close(registry);
long elapsed = (System.nanoTime() - started) / 1_000_000L;
</tspan><tspan x="24" dy="22"> System.out.println(&quot; 강제 닫기가 던진 것 : 없음&quot;);
System.out.println(&quot; 1회차 close() : &quot; + outcome + &quot; (&quot; + ela</tspan><tspan x="24" dy="22">psed + &quot;ms)&quot;);
System.out.println(&quot; 1회차 후 drain 스레드 : &quot; + drainThreads());
System.out.println(&quot; 2회차 cl</tspan><tspan x="24" dy="22">ose() : &quot; + close(registry) + &quot; / drain 스레드 &quot; + drainThreads());
lease.close();
}
public static void main(St</tspan><tspan x="24" dy="22">ring[] args) throws Exception {
System.out.println(&quot;test 가 검증하는 성질 : close() 뒤에 &quot; + DRAIN + &quot; 스레드가 없어</tspan><tspan x="24" dy="22">야 한다&quot;);
System.out.println();
suiteShape();
refusingPool();
slowScheduler();
}
}
JAVA
javac -encodi</tspan><tspan x="24" dy="22">ng UTF-8 -cp &quot;$JAR:$D&quot; -d &quot;$D&quot; &quot;$D/DrainThreadProbe.java&quot;
java -Dstdout.encoding=UTF-8 -cp &quot;$JAR:$D&quot; DrainThreadProbe
</tspan></text>
<text x="24" y="1124" fill="#8b949e" font-size="13" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">cwd: /shared/codebase/clean-architecture-backend-template/src/adapter/outbound/httpclient</tspan></text>
<text x="24" y="1146" fill="#8b949e" font-size="13" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">time: 2026-09-02T13:21:50+00:00 · exit 0</tspan></text>
<line x1="24" y1="1160" x2="1176" y2="1160" stroke="#30363d"/>
<text x="24" y="1200" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">openjdk version &quot;21.0.12&quot; 2026-07-21</tspan></text>
<text x="24" y="1222" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">test 가 검증하는 성질 : close() 뒤에 httpclient-runtime-drain 스레드가 없어야 한다</tspan></text>
<text x="24" y="1244" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"></tspan></text>
<text x="24" y="1266" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">[자원 경계 묶음이 도는 모양] 임차를 쥐지 않고 회전한다</tspan></text>
<text x="24" y="1288" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"> 회전 49회 동안 관측된 drain 스레드 최대치 : 0</tspan></text>
<text x="24" y="1310" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"> 닫힌 세대 : 50 / close() 후 drain 스레드 : 0</tspan></text>
<text x="24" y="1332" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"></tspan></text>
<text x="24" y="1354" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">[강제 닫기 하나가 던지는 경로]</tspan></text>
<text x="24" y="1376" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"> swap 직후 drain 스레드 : 1</tspan></text>
<text x="24" y="1398" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"> 1회차 close() : IllegalStateException: pool refused to close / drain 스레드 1</tspan></text>
<text x="24" y="1420" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"> 거부한 런타임 state : CLOSED / 자원 닫기 호출 1회</tspan></text>
<text x="24" y="1442" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"> 다시 forceClose 후 자원 닫기 호출 : 1회</tspan></text>
<text x="24" y="1464" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"> 2회차 close() : 정상 반환 / drain 스레드 0</tspan></text>
<text x="24" y="1486" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"></tspan></text>
<text x="24" y="1508" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">[강제 닫기가 하나도 던지지 않는데 스레드가 남는 경로]</tspan></text>
<text x="24" y="1530" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"> 마감 작업이 도는 중 drain 스레드 : 1</tspan></text>
<text x="24" y="1552" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"> 강제 닫기가 던진 것 : 없음</tspan></text>
<text x="24" y="1574" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"> 1회차 close() : IllegalStateException: http client drain scheduler did not terminate (5000ms)</tspan></text>
<text x="24" y="1596" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"> 1회차 후 drain 스레드 : 1</tspan></text>
<text x="24" y="1618" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"> 2회차 close() : 정상 반환 / drain 스레드 1</tspan></text>
</svg>