Skip to content

fix: make LOG_DIR creation race-safe with exist_ok=True#9414

Open
pranav-afk wants to merge 1 commit into
makeplane:previewfrom
pranav-afk:fix/9352-log-dir-makedirs-race
Open

fix: make LOG_DIR creation race-safe with exist_ok=True#9414
pranav-afk wants to merge 1 commit into
makeplane:previewfrom
pranav-afk:fix/9352-log-dir-makedirs-race

Conversation

@pranav-afk

@pranav-afk pranav-afk commented Jul 13, 2026

Copy link
Copy Markdown

Description

Makes log directory creation race-safe during concurrent local Docker Compose startups.

On a clean boot, multiple backend containers (API, migrator, worker, beat) can all try to create plane/logs at the same time. The old pattern:

if not os.path.exists(LOG_DIR):
os.makedirs(LOG_DIR)

is not atomic, so one process can create the directory between another’s existence check and makedirs, causing:

FileExistsError: [Errno 17] File exists: '/code/plane/logs'

That can crash containers and leave the UI stuck loading—especially on multi-core hosts or Windows/WSL2 where the race window is wider.

Change: use a single race-safe call in both local and production settings:

os.makedirs(LOG_DIR, exist_ok=True)

Type of Change
• [x] Bug fix (non-breaking change which fixes an issue)
• [ ] Feature (non-breaking change which adds functionality)
• [ ] Improvement (change that would cause existing functionality to not work as expected)
• [ ] Code refactoring
• [ ] Performance improvements
• [ ] Documentation update

Screenshots and Media (if applicable)
N/A — backend settings only.

Test Scenarios
• Remove or clear the local apps/api/plane/logs directory (or start from a clean volume)
• Run docker compose -f docker-compose-local.yml up --build so api/migrator/worker start together
• Confirm containers start without FileExistsError in migrator/api logs
• Confirm the logs directory is created and services continue past settings import
• Re-run with an existing logs directory and confirm startup still succeeds (no-op path)

References
Fixes #9352

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when creating the application’s logging directory.
    • Prevented potential errors caused by concurrent or repeated directory creation in local and production environments.

Concurrent backend containers can hit FileExistsError when creating the
logs directory during a clean local Docker Compose boot. Use exist_ok so
parallel starts do not crash.

Fixes makeplane#9352
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 64c0abb2-bdba-4d47-84b4-ff6c02bbd8a7

📥 Commits

Reviewing files that changed from the base of the PR and between dc9d80b and 9a3fa30.

📒 Files selected for processing (2)
  • apps/api/plane/settings/local.py
  • apps/api/plane/settings/production.py

📝 Walkthrough

Walkthrough

The local and production settings now create LOG_DIR with os.makedirs(..., exist_ok=True), removing the check-then-create race condition while preserving the existing log directory path.

Changes

Log directory initialization

Layer / File(s) Summary
Update log directory initialization
apps/api/plane/settings/local.py, apps/api/plane/settings/production.py
Both environments use idempotent directory creation for LOG_DIR instead of checking for existence first.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: dheeru0198, pablohashescobar

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: making LOG_DIR creation race-safe with exist_ok=True.
Description check ✅ Passed The description matches the template and includes the change summary, type, test scenarios, and references.
Linked Issues check ✅ Passed The PR addresses #9352 by removing the race in log directory creation, which resolves the reported FileExistsError.
Out of Scope Changes check ✅ Passed The production.py update is still directly related to the same LOG_DIR race fix and is not unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

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.

[bug]: local docker setup crashes with FileExistsError in local.py (LOG_DIR race condition)

1 participant