Repository navigation
Description
Affected module
Backend (openmetadata-service)
Describe the bug
EntityLifecycleEventDispatcher keeps its registered handlers in a plain ArrayList. The list is mutated under synchronized (registerHandler / unregisterHandler) but read with no synchronization at all on the dispatch hot path — getApplicableHandlers, getHandlers, getHandlerCount.
ArrayList#removeIf → shiftTailOverGap decrements size first and then writes null into the vacated tail slot. A dispatch already walking the list has bound its stream spliterator fence to the pre-removal size, so it walks straight into the nulled slot and the entity write fails with:
An exception with message [Cannot invoke
"org.openmetadata.service.events.lifecycle.EntityLifecycleEventHandler.getSupportedEntityTypes()"
because "handler" is null] was thrown while processing request.
at EntityLifecycleEventDispatcher.lambda$getApplicableHandlers$13(EntityLifecycleEventDispatcher.java:358)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)
at EntityLifecycleEventDispatcher.getApplicableHandlers(EntityLifecycleEventDispatcher.java:361)
at EntityLifecycleEventDispatcher.onEntityCreated(EntityLifecycleEventDispatcher.java:122)
VectorEmbeddingHandler has priority 200, so it always sorts last — removing it always nulls exactly the slot a concurrent walker is about to read, which is why that handler is the one that trips it.
This is not test-only. Handler registration is not startup-only:
SearchRepository's constructor unregisters and re-registersSearchIndexHandler.SystemRepository.retryInitAndReportError→SearchRepository.initializeVectorSearchService()→OpenSearch/ElasticSearchVectorService.initunregisters and re-registersVectorEmbeddingHandler, reachable from the settings-validation API while requests are in flight.
There is a second, quieter defect at those same call sites: expressing the swap as unregister-then-register leaves a window in which no handler of that name is registered, so an entity write landing in it is silently never indexed.
To Reproduce
Surfaces as a flaky integration-test failure — openmetadata-integration-tests runs classes and methods concurrently (junit-platform.properties), and PatchTableEmbeddingIT (@Execution(CONCURRENT)) unregisters VectorEmbeddingHandler and re-inits the vector service mid-run while other suites are writing entities:
[ERROR] GlossaryTermResourceIT.test_searchGlossaryTermsWithOffsetPagination:2930->createEntity:140
» Api An exception with message [Cannot invoke "...EntityLifecycleEventHandler.getSupportedEntityTypes()"
because "handler" is null] was thrown while processing request.
[ERROR] Tests run: 15598, Failures: 0, Errors: 1, Skipped: 1394
Any suite creating an entity can be the victim; the failing test name varies run to run.
Deterministic reproduction (no stress loop) — park a dispatch mid-walk inside a handler's getSupportedEntityTypes(), unregister the tail handler, release:
- Register handler A (priority 10) whose
getSupportedEntityTypes()blocks on a latch, and handler B (priority 200). - On another thread call
dispatcher.onEntityCreated(...); it blocks inside A. - Call
dispatcher.unregisterHandler("B"). - Release the latch — the dispatch reads the nulled slot and throws the NPE above.
Expected behavior
Registering or unregistering a lifecycle handler must never make a concurrent entity write fail, and must never leave a window in which an entity write sees no handler under a name that is being swapped.
Additional context
The unsynchronized ArrayList dates back to #21921; the removeIf call sites that make it observable landed later. Because it is interleaving-dependent it presents as a new flake rather than a new bug.
Activity
test: reference issue #33711 in the dispatcher regression test
mohityadav766 commentedon Sep 21, 2026
CI occurrence data
Scanned the Integration Tests – PostgreSQL + OpenSearch workflow (the only matrix entry where
PatchTableEmbeddingITis not skipped) for thegetSupportedEntityTypes() … because "handler" is nullsignature.Method: 734 failed runs since 2026-08-25 → sampled up to 6 runs/day → 122 of them had a genuinely failed
Integration Test Lanejob → grepped each of those 122 job logs.2 hits, both in the
parallellane:gh-readonly-queue/main/pr-31213(merge queue on main)FileResourcecreatefix/33685-service-lineage-pipelineCsvExportMultiNodeIT, thenGlossaryTermResourceIT.test_searchGlossaryTermsWithOffsetPaginationNotes:
Two caveats on reading "first seen 2026-09-03":
Code archaeology puts the actual reachability much earlier: the unsynchronized
ArrayListlanded in #21921, and the concurrentremoveIfthat makes it observable has been inPatchTableEmbeddingITsince 2026-03-10. Neither the dispatcher norjunit-platform.propertieshas changed since July, so nothing recent "broke" it — the interleaving simply started landing often enough to notice.mohityadav766 commentedon Sep 21, 2026
Follow-up: extended scan, and why no PR "introduced" this
Extended the scan back to 2026-07-19. Totals across the OpenSearch IT workflow,
Integration Test Lanefailures only:Both hits fall in the later window.
P(both land there by chance) = 0.124— suggestive, not statistically significant, so this does not establish a changepoint.The causal chain is in the code, not in a recent PR:
feat: implement entity lifecycle event delegationArrayList. Neither the field nor the read path has changed since.Add full-server integration test for PATCH table embedding + semantic search@Execution(CONCURRENT)IT callingunregisterHandler("VectorEmbeddingHandler")mid-suite — theremoveIfthat nulls the tail slot while other suites write entities.fix(it): stop flaky integration testsSearchRepository, widening exposure beyond tests.On #31213 (the PR whose merge-queue run produced the earliest observed hit): it merged 2026-09-04 20:07, after the 09-03 21:11 failure, so that run was its pre-merge validation. It touches neither
EntityLifecycleEventDispatchernorSearchRepository, so it cannot introduce this race.It is worth noting honestly that it is not irrelevant either: it wraps every OpenSearch request in
MeteredOpenSearchTransport, so it does change timing across the whole OpenSearch matrix. More per-request latency means more concurrent in-flight requests, which means more chances for a dispatch to overlap the single unregister. That is a plausible window-widener, not a cause. With p=0.124 it cannot be distinguished from coincidence either way.Either way the fix in #33712 is engine-agnostic and does not depend on resolving this.
Fixes open-metadata#33711: publish the lifecycle handler list as an i…