Repository navigation
fix(dedup): fail closed on Logback app extensions, latch XML scan reload at call site, and cover LATCH_ON_CALL methods - #202
Merged
Conversation
…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>
…d scope negative cache per ClassLoader Signed-off-by: slayerjain <shubhamkjain@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the remaining Logback and
LATCH_ON_CALLcoverage-honesty gaps forv2.3.2:Fail closed on ANY app-included
ch/qos/logback/supertype whenAsyncAppenderBaseis active: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.AsyncAppenderBasefirst or app extension first), routesSinkAllowlist.isAllowlistedThreadStartCaller("ch.qos.logback.core.AsyncAppenderBase")throughServerEntries.noteLogbackAsyncAppenderAndCheckSafe(), explores superclass chains ahead of interface lists (cap 64) during read-only.classresource walks, and keeps a bounded per-ClassLoadernegative 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:$jacocoDataprobe array is global per class rather than per thread, andAsyncAppenderBase$Workeris a single shared daemon thread draining events queued by concurrent requests and background threads. Waiting onput()would still allow request A's custom appender/layout/converter/discriminator probes onWorkerto bleed into request B's window, while dropped events (isDiscardable/neverBlock=true) or queue drain delays beyondEND_WAIT_MSwould under-report coverage. Failing closed guarantees coverage never under-reports or cross-contaminates, with zero runtime overhead on standard apps.Latch Logback XML
scan="true"reload at the dispatch call site instead of on class load — while holding XML +AsyncAppender:logback.xmlorlogback-spring.xml) was held asasyncExecutors=falseeven withoutscan="true"orAsyncAppender, because the load-time constant-pool scan latched onScheduledExecutorService.scheduleAtFixedRateinside: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), andch/qos/logback/classic/model/processor/ConfigurationModelHandlerFull(Logback 1.3.10+, 1.4.10+, 1.5.x).addLatchOnDispatchCall) toServerEntries.LATCH_ON_CALLfor all three classes sowrapLatchOnCallhooks everyDISPATCH_PRIMITIVE_METHODScall site (ScheduledExecutorService.scheduleAtFixedRate, etc.) regardless of the enclosing method name (processScanAttrib,detachedPostProcess,scheduleReconfigureOnChangeTaskin 1.5.28+). XML configs withoutscanstay clean, whilescan="true"latchesasyncExecutors=falseimmediately when the reload task is scheduled.AsyncAppenderhold (logback-async-xml-config): An XML config can wireAsyncAppenderto encoders that render raw event arguments, key/value pairs, or markers onAsyncAppender$Worker(for examplelogstash-logback-encoder'sLogstashEncodercalling app getters via Jackson, or Logback'sJsonEncodercalling apptoString()), executing app code off the request thread without any app class extending a Logback type. UntilAsyncAppenderBase.putis tracked as a bounded hand-off drained onEND, XML configuration combined withAsyncAppenderholdsasyncExecutors=falsein either load order and on the runtime worker-start path.RollingFileAppender): ARollingFileAppenderwith a rolling policy is still held asasyncExecutors=falsebecause Logback'sCompressorandTimeBasedArchiveRemoverreference unhookedExecutorService.submitdispatchers. XML configs withoutscanmeasure cleanly for console and plainFileAppenderconfigurations (withoutAsyncAppender).Tests (
HonestProtocolAndAsyncTestandLogbackAsyncSafetyTest):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), andAsyncHealthCheckDecorator.run().HonestProtocolAndAsyncTest.testLogbackAsyncAppenderFailsClosedOnAppIncludedExtensionsandtestLogbackXmlScanReloadLatchesOnlyWhenScanScheduled.LogbackAsyncSafetyTest(4 tests):xmlConfiguredAsyncAppenderHoldsInEitherOrder,scanScheduleLatchesAtCallSiteWhateverItsMethodName,negativeVerdictFromOneLoaderDoesNotHideLogbackBaseInAnother, andwalkThatCouldNotReadEverySupertypeCachesNothing.Verification
All checks ran against committed SHA
0692c0ad686fdd678930f7c70866fae4b8099bfd:mvn -B -pl keploy-sdk -am test):1.8.0_452): 467 run, 0 failures, 0 errors, 10 skipped —BUILD SUCCESS11.0.27): 467 run, 0 failures, 0 errors, 8 skipped —BUILD SUCCESS17.0.15): 467 run, 0 failures, 0 errors, 5 skipped +mvn -P release -Dgpg.skip -DskipTests clean verify+./scripts/smoke-javaagent.sh—BUILD SUCCESS21.0.7): 467 run, 0 failures, 0 errors, 3 skipped —BUILD SUCCESSkeployE+ localkeploy-sdk-2.3.2.jarbuilt from0692c0ad):java-dedupdefault (Spring Boot 2.7, Java 17 native):covered=400, duplicates=382/346, retained=18/54(unchanged)java-dedupXMLlogback-spring.xmlwithoutscan(console, noAsyncAppender):covered=400, duplicates=382/346, retained=18/54(asyncExecutors=true)java-dedupXMLlogback-spring.xmlwithscan="true": held (asyncExecutors=false),covered=400, duplicates=0, retained=400java-dedupXMLlogback-spring.xmlwithAsyncAppender+LogstashEncoder7.2 (JSON stdout verified): held (asyncExecutors=false),covered=400, duplicates=0, retained=400dropwizard-dedup6/6 (Java 8, 17, 21 xnative,native-classpath):covered=200, duplicates=180/142, retained=20/58across all 6 cells (unchanged)