Repository navigation
fix(reindex): stop the mapping guard from permanently killing content indexing (#37038) - #37041
Merged
Merged
Conversation
… indexing (#37038) PR #36499 bounded per-entry reindex mapping so a hung `stat(2)` on network-backed storage could not wedge the reindex thread (#36498). The bound leaks: the semaphore permit is released inside the submitted task's `finally`, which is exactly the code a task that never runs can never reach. The cap is therefore cumulative rather than concurrent — 8 abandoned tasks over the life of the JVM killed content indexing until the node was restarted, while every subsequent entry was charged a retry until it parked at priority 505, past the `priority <= 400` the queue loader reads. Net effect was worse than the bug it fixed: that one froze indexing with the queue intact; this one destroyed the backlog. Four changes: 1. Split the accounting in two and move the tasks to platform threads. Concurrency is now a real concurrency cap whose permit the *caller* releases in a `finally` that always executes; abandonment is a separate counter, only decremented by a task that actually finishes, whose ceiling opens a circuit breaker. Platform threads are what make this safe: an abandoned virtual thread keeps pinning a carrier from a JVM-wide pool of `availableProcessors()` (file I/O does not unmount), which is what forced the release into the task body in the first place. An abandoned platform thread costs only its own stack and steals nothing, and both counters are bounded, so worst-case thread count is `maxConcurrent + maxAbandoned`. 2. Never charge a retry for a pool rejection. `ReindexPoolExhaustedException` distinguishes "the pool is unavailable" from `ReindexMappingTimeoutException` ("this entry's own mapping overran"), and only the latter reaches `markAsFailed`. A rejected entry is left byte-for-byte untouched. 3. Fail loudly instead of silently. A new `reindex-mapping` health check reports stalled indexing, and an open circuit makes the reindex thread back off (`REINDEX_THREAD_SLEEP_WHEN_DEGRADED`, default 30s) rather than spinning the journal at `SLEEP_ON_ERROR` speed. The exhaustion log is throttled and no longer asserts that storage is down unconditionally. 4. Move the index bulk enqueue out of the guarded region. `BulkProcessor.add()` blocks on the client's in-flight semaphore (`REINDEX_THREAD_CONCURRENT_REQUESTS` defaults to 1) and its backoff budget is 20s x 10 = 200s, greater than the 120s mapping timeout — so index slowness alone could trigger the guard with no storage fault at all. Mapping now returns `MappedDocument`s and the enqueue happens outside the timeout. Because the abandonment counter heals when a stuck task eventually returns, recovery no longer needs a restart. New config: `REINDEX_CONTENTLET_MAPPING_MAX_ABANDONED` (32), `REINDEX_THREAD_SLEEP_WHEN_DEGRADED` (30000). `REINDEX_CONTENTLET_MAPPING_TIMEOUT_SECONDS=0` still disables the guard entirely. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
15 tasks
Contributor
|
Claude finished @wezell's task in 4m 48s —— View job Reindex mapping guard fix — reviewI traced the full changed set (10 files) against Verified correct:
New Issues
Note (non-blocking, no action needed)
No critical or high-severity issues. The design is sound and the accounting is provably leak-free. · branch |
…y simulates dead storage
`poolRejectionLeavesTheJournalRowUntouched` failed 4/4 in MainSuite 2b. The
production guard was correct — the log shows the circuit opening as designed
("1 of 1 abandoned slots now in use") — but the test's simulated hang let
`InterruptedException` escape `CountDownLatch.await`.
The timeout path calls `future.cancel(true)`, so the interrupt ended the task,
its `finally` ran, and the abandoned counter went straight back to 0. The circuit
closed between the two entries and the second one mapped normally instead of
being rejected.
That is the right behavior for interruptible work — a task that answers an
interrupt is slow, not wedged, and must return its slot (covered by
`interruptibleSlowTaskIsFreedAndNotCountedAsAbandoned`). The test was simulating
slow storage while asserting the consequences of dead storage.
Swallow the interrupt, matching the unit-test helper and a real uninterruptible
native stat(2). Also strengthens the pre-existing
`hungMappingFailsItsJournalEntryAndTheBatchContinues`, which was passing while
only ever simulating an interruptible stall.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
🐳 PR Docker test imageLatest build for commit docker pull dotcms/dotcms-test:pr-37041-issue-37038-reindex-mapping-permit-leak
docker pull dotcms/dotcms-test:pr-37041-issue-37038-reindex-mapping-permit-leak_1e471ec |
fabrizzio-dotCMS
temporarily deployed
to
manual
August 13, 2026 15:15 — with
GitHub Actions
Inactive
6 tasks
Ref #37038. The reindex loop logged "Shutdown detected, stopping reindex operations" via Logger.info on every iteration while draining, spamming the log during shutdown. Switched to Logger.infoEvery to throttle it.
wezell
approved these changes
Aug 14, 2026
wezell
left a comment
Member
There was a problem hiding this comment.
Tested against 400,000 contentlets. 3 legitimately failed, as they should have. Looks good. Added a logging change to prevent log span.
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.
What
Fixes #37038 — a regression shipped in 26.07.13-01 by PR #36499 (the fix for #36498).
The reindex mapping guard leaks its semaphore permits permanently. After 8 abandoned mapping tasks, a node stops indexing content until it is restarted, and every entry rejected in the meantime is charged a retry until it parks at priority 505 — past the
priority <= 400the queue loader reads. The net effect was worse than the bug it fixed: #36498 froze indexing with the queue intact and recovered on restart; this froze indexing and destroyed the backlog.Confirmed on a customer's staging and production environments: 315,030 journal entries in terminal ERROR state across 6 days, 303,282 distinct contentlets never indexed, 99.3% of them ordinary content saves.
Root cause
inFlight.release()lived inside thefinallyof the submitted task — which is exactly the code a task that never runs can never reach:That placement was not sloppiness, it was forced. Tasks ran on virtual threads, and file I/O does not unmount a virtual thread from its carrier. The carrier pool is
availableProcessors()— 2–4 in a container, shared with every other virtual thread in the JVM — so an abandoned task keeps consuming a globally scarce resource. The cap therefore had to count abandoned work, which forced its release into the task body, which is the leak. And withmaxThreadsat 8 over 2–4 carriers, the cap sat above the point at which the carrier pool was already fully pinned, so it could never bind before starvation did.The four changes
1. Two counters, and platform threads to make that safe
REINDEX_CONTENTLET_MAPPING_MAX_THREADS, 8)finallythat always runsREINDEX_CONTENTLET_MAPPING_MAX_ABANDONED, 32)Moving the tasks to platform threads is what makes caller-side release safe: an abandoned platform thread costs only its own stack (~1MB) and steals nothing from anyone else, so releasing the concurrency permit on timeout cannot let a wedge go unaccounted for. Both counters are bounded, so the worst-case live thread count is
maxConcurrent + maxAbandoned. Threads are daemons, so a thread wedged in native I/O can never hold up JVM shutdown.Not keeping virtual threads was deliberate. The original argument for them — abandoning one is free, and a hung native
statignoresinterrupt()so abandoning is the only move — is real, but it buys little once the cap is 8 anyway, and it costs a shared carrier pool. Seedocs/backend/VIRTUAL_THREADS.md(#36900) for the socket-vs-file rule.Because the abandonment counter heals when a stuck task eventually returns, recovery no longer requires a restart.
2. A pool rejection is never charged to the entry
ReindexPoolExhaustedException(infrastructure) is now distinct fromReindexMappingTimeoutException(this entry's own mapping overran). Only the latter reachesmarkAsFailed. A rejected entry is left byte-for-byte untouched — same priority, no failure cause — so it is retried later instead of marching towardPriority.ERROR.A momentarily saturated pool defers just that entry; an open circuit aborts the batch so the loop can back off.
3. The failure is now visible and self-limiting
reindex-mappinghealth check (MONITOR_MODEby default, not a liveness check since the guard self-heals) reportingabandonedMappings/indexingStalled.REINDEX_THREAD_SLEEP_WHEN_DEGRADED(30s) instead of spinning the journal atSLEEP_ON_ERROR(500ms) speed.4. The index enqueue moved out of the guarded region
BulkProcessor.add()blocks on the client's in-flight semaphore (REINDEX_THREAD_CONCURRENT_REQUESTSdefaults to 1) and its backoff budget is20s × 10 = 200s— greater than the 120s mapping timeout. Elasticsearch slowness alone was sufficient to trigger the guard, with no storage fault at all.Mapping now returns
MappedDocuments (the storage-touching half) andenqueueMappedDocumentsruns on the caller thread, outside the timeout.Tests
71 unit tests green (
ReindexMappingRunnerTest,ContentletIndexAPIImplMappingTimeoutTest,ReindexThreadUnitTest, and the rest of theContentletIndexAPIImpl*Testfamily).New coverage for the regression specifically:
moreTimeoutsThanTheConcurrencyCapDoesNotDisableTheRunner—cap + 3timeouts, then a healthy task must still succeed. This is the test that fails on the old code.abandonmentCeilingOpensTheCircuit/circuitClosesWhenAbandonedTasksReturn— the ceiling trips, then heals with no restart.interruptibleSlowTaskIsFreedAndNotCountedAsAbandoned— merely-slow work is not booked as abandoned.asyncTaskRunsOnNamedPlatformThread— asserts not virtual, so a future well-meaning swap back is caught.poolRejectionNeverFailsTheJournalEntry,poolRecoversWhenAbandonedTaskFinishes— wiring level.ContentletIndexAPIImplMappingTimeoutIT#poolRejectionLeavesTheJournalRowUntouched— the data-loss half against real SQL: priority unchanged,index_valnull. Registered inMainSuite2b.Deploying to an already-affected instance
This PR removes the need for the workaround, but it does not clean up rows already parked by it. Any instance that ran 26.07.13-01 or later still needs the requeue:
DOT_REINDEX_CONTENTLET_MAPPING_TIMEOUT_SECONDS=0remains a full off switch (runs the mapping inline, no executor, no semaphore) and still works with an open circuit, so it stays available as a mitigation.New configuration
REINDEX_CONTENTLET_MAPPING_MAX_ABANDONEDREINDEX_THREAD_SLEEP_WHEN_DEGRADEDNot included
Recovering parked rows through a maintenance action rather than manual SQL. It is in the issue's acceptance criteria and is worth doing, but it is a UI/maintenance-portlet change rather than part of this defect's mechanism.
🤖 Generated with Claude Code
This PR fixes: #37038