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

Merged
slayerjain merged 3 commits into
mainfrom
fix/logback-custom-ext-and-latch-rows
Nov 30, 2026
Merged

slayerjain merged 3 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 keeps a bounded per-ClassLoader negative cache (WeakHashMap<ClassLoader, Set<String>>, global cap 32,768, no bootstrap cache, no caching of incomplete walks) so one loader's verdict never hides a Logback base class in another loader.

    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 — while holding XML + AsyncAppender:

    • 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),
      • ch/qos/logback/classic/model/processor/ConfigurationModelHandler (Logback 1.3.0–1.3.8 and 1.4.0–1.4.8), and
      • ch/qos/logback/classic/model/processor/ConfigurationModelHandlerFull (Logback 1.3.10+, 1.4.10+, 1.5.x).
    • Added call-site latching (addLatchOnDispatchCall) to ServerEntries.LATCH_ON_CALL for all three classes so wrapLatchOnCall hooks every DISPATCH_PRIMITIVE_METHODS call site (ScheduledExecutorService.scheduleAtFixedRate, etc.) regardless of the enclosing method name (processScanAttrib, detachedPostProcess, scheduleReconfigureOnChangeTask in 1.5.28+). XML configs without scan stay clean, while scan="true" latches asyncExecutors=false immediately when the reload task is scheduled.
    • XML + AsyncAppender hold (logback-async-xml-config): An XML config can wire AsyncAppender to encoders that render raw event arguments, key/value pairs, or markers on AsyncAppender$Worker (for example logstash-logback-encoder's LogstashEncoder calling app getters via Jackson, or Logback's JsonEncoder calling app toString()), executing app code off the request thread without any app class extending a Logback type. Until AsyncAppenderBase.put is tracked as a bounded hand-off drained on END, XML configuration combined with AsyncAppender holds asyncExecutors=false in either load order and on the runtime worker-start path.
    • Scope note (RollingFileAppender): A RollingFileAppender with a rolling policy is still held as asyncExecutors=false because Logback's Compressor and TimeBasedArchiveRemover reference unhooked ExecutorService.submit dispatchers. XML configs without scan measure cleanly for console and plain FileAppender configurations (without AsyncAppender).
  3. Tests (HonestProtocolAndAsyncTest and LogbackAsyncSafetyTest):

    • 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().
    • HonestProtocolAndAsyncTest.testLogbackAsyncAppenderFailsClosedOnAppIncludedExtensions and testLogbackXmlScanReloadLatchesOnlyWhenScanScheduled.
    • LogbackAsyncSafetyTest (4 tests): xmlConfiguredAsyncAppenderHoldsInEitherOrder, scanScheduleLatchesAtCallSiteWhateverItsMethodName, negativeVerdictFromOneLoaderDoesNotHideLogbackBaseInAnother, and walkThatCouldNotReadEverySupertypeCachesNothing.

Verification

All checks ran against committed SHA 0692c0ad686fdd678930f7c70866fae4b8099bfd:

  • Unit test matrix (mvn -B -pl keploy-sdk -am test):
    • JDK 8 (1.8.0_452): 467 run, 0 failures, 0 errors, 10 skipped — BUILD SUCCESS
    • JDK 11 (11.0.27): 467 run, 0 failures, 0 errors, 8 skipped — BUILD SUCCESS
    • JDK 17 (17.0.15): 467 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): 467 run, 0 failures, 0 errors, 3 skipped — BUILD SUCCESS
  • Live end-to-end sample lanes (keployE + local keploy-sdk-2.3.2.jar built from 0692c0ad):
    • 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 (console, no AsyncAppender): 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
    • java-dedup XML logback-spring.xml with AsyncAppender + LogstashEncoder 7.2 (JSON stdout verified): 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
…d scope negative cache per ClassLoader

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
@slayerjain
slayerjain merged commit b52193c into main Nov 30, 2026
5 checks passed
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