PromptBase
PromptBase SelectGet Select
Close icon
General
Home
Marketplace
Create
Hire
Login
Chat
Sell
Explore

Skill Details

Runtime
Any model
Example user message
[userMessage]: Our Java/Spring service lazily creates a shared rules engine the first time it is needed. The getter uses double-checked locking but the field is not volatile, and construction registers plugins into mutable maps before returning. Under a deterministic two-thread test, the second caller can sometimes observe missing plugin entries. Repair locally with barriers around construction/publication. Preserve singleton scope and plugin order. Do not contact production services or replace the rules engine library.
Example agent response
# 1. Repair Decision **Decision: UNSAFE DOUBLE-CHECKED PUBLICATION CAN EXPOSE PARTIALLY INITIALIZED SINGLETON STATE — SAFE LOCAL PATCH AVAILABLE; production schedules remain unverified.** # 2. Scope & Safety Boundary Reviewed lazy getter, singleton field, rules-engine construction, plugin registration, shutdown/disposal, tests, metrics, and docs. Not accessed: production services, live plugin registry, production threads, or external dependencies. # 3. Initialization Source Register - singleton field: non-volatile; - getter: double-checked locking; - constructor/factory: creates engine then mutates plugin maps; - publication: field can become visible without an explicit safe-publication guarantee; - shutdown: disposes shared engine once; - retry: initialization exceptions propagate today. # 4. Concurrent First-Use Timeline Thread A sees null → enters lock → begins engine construction/plugin registration. Thread B later reads singleton outside lock. Without safe publication, B may observe the reference without all constructed state being guaranteed visible. # 5. Race Findings Confirmed: - double-checked locking lacks required publication primitive; - mutable initialization occurs before READY state; - test has no explicit state model; - singleton scope itself is not the defect. # 6. Canonical Initialization State Machine `EMPTY -> INITIALIZING -> READY` or `EMPTY -> INITIALIZING -> FAILED` Only READY exposes the engine reference. Construction and plugin registration finish before publication. Failure does not publish a partial engine. Existing retry behavior after a later call is preserved only if current contract permits it. # 7. Repair Applied Prepared: - runtime-safe lazy holder / volatile-backed publication pattern appropriate to repository style; - construction moved into one factory that returns only a fully registered engine; - no field publication before plugin registration completes; - failed construction disposes owned partial resources; - shutdown obtains/disposes only READY singleton; - plugin order unchanged. # 8. Failure / Retry / Invalidation Safety Initialization exception is surfaced. Partial object is never cached. If the existing contract permits retry after failure, state returns safely to EMPTY after owned cleanup; otherwise failure is memoized explicitly. No silent infinite retry loop is introduced. # 9. Deterministic Initialization Test Matrix 1. Two callers start first use simultaneously. 2. Only one engine construction occurs. 3. Second caller never sees partial plugin map. 4. Plugin order matches baseline. 5. Construction failure publishes no engine. 6. Retry behavior matches declared policy. 7. 100 concurrent callers receive same READY instance. 8. Shutdown disposes instance once. 9. Shutdown never disposes partial unpublished object. 10. Existing serial behavior unchanged. # 10. Observability & Rollout Added init attempt/success/failure counters, concurrent waiter count, duplicate construction prevented, and disposal count without logging plugin secrets. # 11. Files Modified - `RulesEngineProvider.java` - `RulesEngineFactory.java` - `RulesEngineProviderConcurrencyTest.java` - `docs/rules-engine-lifecycle.md` # 12. Commands Executed - `./gradlew test --tests '*RulesEngineProviderConcurrencyTest'` - `./gradlew check` # 13. Validation Local results: single construction PASS; safe publication PASS; plugin completeness/order PASS; failure cleanup PASS; shutdown-once PASS; Gradle checks PASS. Not verified: production thread schedules or third-party engine internal thread safety after initialization. # 14. Remaining Decisions & Handoff Owner decision: whether a failed initialization should be retryable on a later request or remain failed until process restart. **Handoff: PATCH READY FOR LOCAL REVIEW — SINGLETON PUBLICATION MADE SAFE AND PARTIAL INITIALIZATION BLOCKED; PRODUCTION SCHEDULING NOT VERIFIED.**
Cursor Skill

Repair Lazy Initialization Races

Add to Cart
PromptBase Select
Get this skill + 9 more with Select$14 your first month, then $19/mo$14 first month, then $19/mo
View Select
Instant accessInstant access
Usage rightsCommercial use
Money-back guaranteeMoney‑back
By purchasing this skill, you agree to our terms of service
Tested icon
Guide icon
Free credits icon
Repair lazy initialization races across shared clients, singletons, registries, caches, and config snapshots. Finds duplicate construction, partial publication, unsafe double-checked locking, async first-use herds, poisoned failure memoization, reload races, and shutdown conflicts; then prepares bounded repository patches, explicit initialization state, deterministic concurrency tests, safe failure/retry ownership, and observability without touching production dependencies.
...more
Added over 1 month ago
Report
Browse Marketplace