Skip to content

Adding code to clear Spring contexts before/after site context init#851

Merged
sumerjabri merged 1 commit into
craftercms:developfrom
avasquez614:bugfix/8734-develop
Jun 13, 2026
Merged

Adding code to clear Spring contexts before/after site context init#851
sumerjabri merged 1 commit into
craftercms:developfrom
avasquez614:bugfix/8734-develop

Conversation

@avasquez614

@avasquez614 avasquez614 commented Jun 12, 2026

Copy link
Copy Markdown
Member

craftercms/craftercms#8734

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved thread context state management in background maintenance operations to eliminate potential context leakage between concurrent tasks and ensure proper request and locale context handling throughout the entire task lifecycle
    • Added enhanced error logging and centralized monitoring for background maintenance task execution to improve overall system reliability, stability, and troubleshooting capabilities

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d703e077-9ae3-43e5-ba53-0a4c20238754

📥 Commits

Reviewing files that changed from the base of the PR and between ff9bfcc and 650f63f.

📒 Files selected for processing (1)
  • src/main/java/org/craftercms/engine/service/context/SiteContext.java

Walkthrough

SiteContext now uses a custom single-thread ThreadPoolExecutor that clears Spring RequestContextHolder and LocaleContextHolder before and after each maintenance task, preventing thread-local context pollution. Core executor implementation includes exception logging. Minor Javadoc reflowing and comment adjustments are included throughout.

Changes

SiteContext Thread Context Management

Layer / File(s) Summary
Thread context cleanup executor implementation
src/main/java/org/craftercms/engine/service/context/SiteContext.java
Imports LocaleContextHolder and RequestContextHolder. Replaces simple single-thread executor with custom ThreadPoolExecutor that clears Spring thread context before and after task execution and logs exceptions from directly executed tasks. Adds clearSpringThreadContexts() helper. Related initialization comments updated.
Javadoc, comments, and cosmetic formatting updates
src/main/java/org/craftercms/engine/service/context/SiteContext.java
Class and method Javadoc reflow, inline comments in publishEvent() describing request-attribute behavior, and line wrapping in toString(), isTranslationEnabled(), and stopWatch formatting. No logic changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only provides a GitHub issue link without fulfilling the template requirement of a ticket reference or full description of what's in the PR. Expand the description to include a full explanation of the changes, why they were made, and how they address the referenced issue.
Docstring Coverage ⚠️ Warning Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding code to clear Spring contexts (RequestContextHolder and LocaleContextHolder) before/after site context initialization.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@avasquez614 avasquez614 marked this pull request as ready for review June 12, 2026 20:17
@avasquez614 avasquez614 requested a review from sumerjabri as a code owner June 12, 2026 20:17
@sumerjabri sumerjabri merged commit 024d5e0 into craftercms:develop Jun 13, 2026
3 of 4 checks passed
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.

2 participants