daniancu opened a new pull request, #20:
URL: https://github.com/apache/sling-org-apache-sling-discovery-oak/pull/20

   ## Summary
   
   `OakDiscoveryService.doUpdateProperties()` can block the Felix start-level 
thread indefinitely on Oak's `CommitQueue` during framework shutdown. When a 
`PropertyProvider` unbind/update callback fires (from a higher-start-level 
bundle that stops before `discovery.oak`), DS invokes the callback 
synchronously on the Felix start-level thread. That callback calls 
`ResourceResolver.commit()`, which parks on a `CountDownLatch` inside 
`CommitQueue` and never returns. The JVM only exits when forcibly killed by the 
surrounding process manager; during that window the instance remains visible in 
the discovery topology, delaying cluster convergence.
   
   The fix introduces a `volatile boolean deactivating` flag that 
short-circuits `doUpdateProperties()` before any repository traffic begins, 
latched from two triggers:
   
   1. **First line of `deactivate()`** — covers standalone component 
deactivation.
   2. **Inline poll of the system bundle state** inside `isShuttingDown()` — 
covers the observed failure path where `deactivate()` is never reached. Per the 
OSGi spec the system bundle transitions to `STOPPING` before any other bundle 
begins stopping, so the poll sees it on the very first guarded callback.
   
   The system bundle reference is cached at activation via 
`FrameworkUtil.getBundle(...)` so unit tests without an OSGi runtime degrade 
cleanly to the `deactivate()`-only path.
   
   The fix does **not** interrupt an in-flight commit — it only prevents new 
commits from starting once shutdown has begun.
   
   ## Tests
   
   - `testIsShuttingDownAfterDeactivate` — deactivate flips the flag; 
subsequent callbacks succeed without touching the repository.
   - `testInlineSystemBundleStateFallback` — system bundle `STOPPING` state 
latches the flag without `deactivate()` being called (the primary failure path).
   - `testInvalidatedSystemBundleTreatedAsShuttingDown` — 
`IllegalStateException` from `getState()` is treated as shutting down.
   - `testCacheSystemBundleWithInvalidatedContextLatchesDeactivating` — 
`IllegalStateException` from `getBundleContext()` at activation latches 
`deactivating` immediately.
   - `testActivatedServiceSkipsResourceResolverWhenSystemBundleStopping` — main 
acceptance criterion: `Mockito.verifyNoInteractions(rrfMock)` confirms no 
repository write is attempted once the system bundle is `STOPPING`, even with 
the service fully activated.
   
   All 22 tests pass (`OakDiscoveryServiceTest` + 
`its.OakDiscoveryServiceTest`).
   
   ## Related
   
   - SLING-5382, SLING-3389, SLING-10204


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to