Skip to content

UNOMI-939/940: Scheduler dispatch and cache refresh race fixes#792

Merged
sergehuber merged 4 commits into
masterfrom
UNOMI-939-940-scheduler-cache
Jul 1, 2026
Merged

UNOMI-939/940: Scheduler dispatch and cache refresh race fixes#792
sergehuber merged 4 commits into
masterfrom
UNOMI-939-940-scheduler-cache

Conversation

@sergehuber

@sergehuber sergehuber commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Plain-language summary

Apache Unomi runs background jobs on a schedule. Examples include cache refresh and maintenance tasks. It also keeps in-memory copies of configuration such as rules and segments.

Under load or during shutdown, several bugs were possible. The same job could run twice. A recurring job could not be stopped at some times. A scheduled cache reload could overwrite data that had just been saved.

This PR fixes these timing bugs. Operators and connected systems should see more stable behavior.

What changed

Scheduler

  • Claim a task in one step before starting it. Only one thread can start the same task at a time.
  • Allow cancel when a recurring task is briefly marked completed between runs. Before, cancel had no effect in that state.
  • Improve shutdown handling. Recovery no longer overwrites the "interrupted by shutdown" state. A failed start no longer leaves a task blocked forever.

In-memory caches (rules, segments, definitions, etc.)

  • Add a read/write lock per item type.
  • A background refresh cannot run at the same time as a direct save or delete. This stops old data from replacing new data in the cache.

Tests

  • Add a concurrency test for the cache lock.
  • Increase timeouts on some unit tests that timed out on slow CI.

Test plan

  • mvn -pl :unomi-services,:unomi-services-common,:unomi-tracing-impl -am test (targeted)
  • CI integration tests

References

UNOMI-939, UNOMI-940, UNOMI-929

@sergehuber sergehuber force-pushed the UNOMI-939-940-scheduler-cache branch from eeb59ee to 2de4368 Compare June 30, 2026 14:23
Forces saveItem() and refreshTypeCache() to interleave via controlled
latches instead of relying on timing-dependent integration tests to
occasionally catch a regression in the per-item-type ReadWriteLock.
@sergehuber sergehuber merged commit 5f8f4dc into master Jul 1, 2026
6 checks passed
@sergehuber sergehuber deleted the UNOMI-939-940-scheduler-cache branch July 1, 2026 04:09
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