Skip to content

fix(dedup): fail closed on Logback app extensions, latch XML scan reload at call site, and cover LATCH_ON_CALL methods - #202

Open
slayerjain wants to merge 2 commits into
mainfrom
fix/logback-custom-ext-and-latch-rows
Open

slayerjain wants to merge 2 commits into
mainfrom
fix/logback-custom-ext-and-latch-rows

Conversation

@slayerjain

@slayerjain slayerjain commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes the remaining Logback and LATCH_ON_CALL coverage-honesty gaps for v2.3.2:

  1. Fail closed on ANY app-included ch/qos/logback/ supertype when AsyncAppenderBase is active:

    • Replaces the enumerated Logback extension list with a package-prefix supertype rule (ch/qos/logback/), direct or transitive, so every Logback worker-invoked SPI (Appender, Encoder, Layout, Converter, Filter, TurboFilter, Discriminator/AbstractDiscriminator, StatusListener, IThrowableRenderer, ConnectionSource, RollingPolicy, TriggeringPolicy, and any future SPI) fails closed by construction.
    • Tracks both load orders (AsyncAppenderBase first or app extension first), routes SinkAllowlist.isAllowlistedThreadStartCaller("ch.qos.logback.core.AsyncAppenderBase") through ServerEntries.noteLogbackAsyncAppenderAndCheckSafe(), explores superclass chains ahead of interface lists (cap 64) during read-only .class resource walks, and negatively caches fully resolved non-Logback supertypes (bounded at 32,768 entries) to avoid repeated .class reads on large apps.
    • Standard Spring Boot / Dropwizard apps (framework-only Logback classes) and sync-only apps with custom Logback extensions remain clean.

    Why fail-closed instead of tracking AsyncAppenderBase.put:

    • JaCoCo's $jacocoData probe array is global per class rather than per thread, and AsyncAppenderBase$Worker is a single shared daemon thread draining events queued by concurrent requests and background threads. Waiting on put() would still allow request A's custom appender/layout/converter/discriminator probes on Worker to bleed into request B's window, while dropped events (isDiscardable / neverBlock=true) or queue drain delays beyond END_WAIT_MS would under-report coverage. Failing closed guarantees coverage never under-reports or cross-contaminates, with zero runtime overhead on standard apps.
  2. Latch Logback XML scan="true" reload at the dispatch call site instead of on class load:

    • Previously, any application configuring Logback via XML (logback.xml or logback-spring.xml) was held as asyncExecutors=false even without scan="true" or AsyncAppender, because the load-time constant-pool scan latched on ScheduledExecutorService.scheduleAtFixedRate inside ch/qos/logback/classic/joran/action/ConfigurationAction (Logback 1.2.x) and ch/qos/logback/classic/model/processor/ConfigurationModelHandlerFull (Logback 1.3.x–1.5.x).
    • Both classes unconditionally enter processScanAttrib / detachedPostProcess on every <configuration> element and return early unless scan is enabled. Added call-site latching (addLatchOnDispatchCall) to ServerEntries.LATCH_ON_CALL for both classes so wrapLatchOnCall hooks every DISPATCH_PRIMITIVE_METHODS call site (ScheduledExecutorService.scheduleAtFixedRate, etc.) directly before invocation, firing RequestGate.noteRuntimeUntrackedDispatch("logback-scan-reload:...") only when a scan="true" reload task is actually scheduled.
    • XML-configured apps without scan (including Spring Boot logback-spring.xml with <include> and <springProfile>) now retain asyncExecutors=true, while scan="true" latches asyncExecutors=false immediately.
  3. Add all missing LATCH_ON_CALL test rows and call-site / package-rule tests (HonestProtocolAndAsyncTest):

    • Direct mutant-killing rows for ScheduledReporter.getScheduledFuture (metrics 4.2.x exact 5-arg signature), JerseyRequestTimeoutHandler.setSuspendTimeout, ChunkedOutput.flushQueue, ChunkedOutput.setContext, HealthCheckRegistry.runHealthChecks(ExecutorService, Object) (2-arg overload + sync overloads stay clean), and AsyncHealthCheckDecorator.run().
    • testLogbackAsyncAppenderFailsClosedOnAppIncludedExtensions: covers framework-only clean, all direct Logback extension categories including AbstractDiscriminator, StatusListener, and IThrowableRenderer, both load orders, SinkAllowlist runtime fallback, transitive framework/pre-loaded hierarchies, superclass-first priority behind 20 wide interfaces, and negative-cache reuse.
    • testLogbackXmlScanReloadLatchesOnlyWhenScanScheduled: covers both ConfigurationAction (1.2.x) and ConfigurationModelHandlerFull (1.3.x–1.5.x) — clean on class load, clean on scan=false, immediate pre-call latch on scan=true (even with a mock ScheduledExecutorService), and re-transform idempotency.

Verification

All checks ran against committed SHA d09336607526a8c3e024a9a5a1b702bf93b009e0:

  • Unit test matrix (mvn -B -pl keploy-sdk -am test):
    • JDK 8 (1.8.0_452): 463 run, 0 failures, 0 errors, 10 skipped — BUILD SUCCESS
    • JDK 11 (11.0.27): 463 run, 0 failures, 0 errors, 8 skipped — BUILD SUCCESS
    • JDK 17 (17.0.15): 463 run, 0 failures, 0 errors, 5 skipped + mvn -P release -Dgpg.skip -DskipTests clean verify + ./scripts/smoke-javaagent.sh — BUILD SUCCESS
    • JDK 21 (21.0.7): 463 run, 0 failures, 0 errors, 3 skipped — BUILD SUCCESS
  • Mutant-kill proof (10/10 killed by assertion):
    • drop_getScheduledFuture, drop_setSuspendTimeout, drop_flushQueue, drop_setContext, narrow_runHealthChecks_to_1arg, drop_AsyncHealthCheckDecorator_run, disable_inspectLogbackAsyncExtension, drop_sinkallowlist_logback_gate, drop_ConfigurationAction_latch, drop_ConfigurationModelHandlerFull_latch
  • Real-JVM Logback 1.2.13 + 1.5.12 matrix (12/12 pass):
    • s0-async-plain (XML no scan, stock AsyncAppender): clean (DISPATCHERS=[], RUNTIME_LATCH=false) on both 1.2.13 and 1.5.12
    • s1-async-converter (XML + AsyncAppender + app converter via intermediate): latched (logback-async-app-extension) on both
    • s2-async-sift (XML + AsyncAppender + SiftingAppender + app TenantDiscriminator): latched (logback-async-app-extension) on both
    • s3-sync-converter (XML sync + app converter): clean on both
    • s4-scan-true (XML scan="true"): latched (RUNTIME_LATCH=true) on both
    • s5-scan-false (XML scan="false"): clean on both
  • Live end-to-end sample lanes (keployE + local keploy-sdk-2.3.2.jar):
    • java-dedup default (Spring Boot 2.7, Java 17 native): covered=400, duplicates=382/346, retained=18/54 (unchanged)
    • java-dedup XML logback-spring.xml without scan (<include> + <springProfile>): covered=400, duplicates=382/346, retained=18/54 (asyncExecutors=true)
    • java-dedup XML logback-spring.xml with scan="true": held (asyncExecutors=false), covered=400, duplicates=0, retained=400
    • dropwizard-dedup 6/6 (Java 8, 17, 21 x native, native-classpath): covered=200, duplicates=180/142, retained=20/58 across all 6 cells (unchanged)

…ase and cover all LATCH_ON_CALL methods

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
…gback XML scan reload at call site

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
@slayerjain slayerjain changed the title fix(dedup): fail closed on app Logback extensions with AsyncAppenderBase and cover all LATCH_ON_CALL methods fix(dedup): fail closed on Logback app extensions, latch XML scan reload at call site, and cover LATCH_ON_CALL methods Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant