Skip to content

fix(api): prevent race condition when creating logs directory (Issue #9352)#9353

Open
geeked-anshuk666 wants to merge 1 commit into
makeplane:previewfrom
geeked-anshuk666:fix/local-settings-race-condition
Open

fix(api): prevent race condition when creating logs directory (Issue #9352)#9353
geeked-anshuk666 wants to merge 1 commit into
makeplane:previewfrom
geeked-anshuk666:fix/local-settings-race-condition

Conversation

@geeked-anshuk666

@geeked-anshuk666 geeked-anshuk666 commented Jul 3, 2026

Copy link
Copy Markdown

Description

Fixes a startup crash in the local Docker environment where backend containers (api, migrator, worker, beat-worker) concurrently load Django configurations and trigger a race condition on directory creation.

Root cause: Multiple Django processes checking if not os.path.exists(LOG_DIR) simultaneously on boot, resulting in a slower process throwing a FileExistsError on os.makedirs(LOG_DIR).

Fix: Changed os.makedirs(LOG_DIR) to use exist_ok=True to make the directory creation thread-safe and prevent the startup crash.

Type of Change

  • 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 startup fix)

Test Scenarios

  1. Perform a clean docker-compose build (ensure the logs directory doesn't exist locally).
  2. Run docker compose -f docker-compose-local.yml up -d --build.
  3. Check container logs (docker logs plane-migrator-1 and docker logs plane-api-1).
  4. Before: Containers exit with FileExistsError: [Errno 17] File exists: '/code/plane/logs'.
  5. After: All containers boot up, wait for database migrations, and start successfully without any crashes.

References

Fixes #9352

Summary by CodeRabbit

  • Bug Fixes
    • Improved app startup reliability by ensuring the log directory is created automatically when needed.

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The LOG_DIR directory creation logic in local development settings was changed from a manual existence check followed by os.makedirs(LOG_DIR) to a single unconditional os.makedirs(LOG_DIR, exist_ok=True) call, preventing a race condition during concurrent container startup.

Changes

Local Settings Fix

Layer / File(s) Summary
LOG_DIR creation checkpoint
apps/api/plane/settings/local.py
Directory creation for LOG_DIR now uses os.makedirs(LOG_DIR, exist_ok=True) instead of checking existence before calling os.makedirs.

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: preventing the LOG_DIR race condition in local API startup.
Description check ✅ Passed The description covers the bug, root cause, fix, tests, and reference, matching the template well.
Linked Issues check ✅ Passed The change matches issue #9352 by making LOG_DIR creation safe with exist_ok=True in local settings.
Out of Scope Changes check ✅ Passed The diff appears narrowly scoped to the reported race condition fix and includes no unrelated changes.
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/api/plane/settings/local.py (1)

37-37: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Same race condition likely exists in production.py.

apps/api/plane/settings/production.py uses the same check-then-mkdir pattern for LOG_DIR this PR fixes here. Consider applying the identical exist_ok=True fix there for consistency, since production containers can also start concurrently.

♻️ Suggested fix for production.py
 LOG_DIR = os.path.join(BASE_DIR, "logs")  # noqa

-if not os.path.exists(LOG_DIR):
-    os.makedirs(LOG_DIR)
+os.makedirs(LOG_DIR, exist_ok=True)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/api/plane/settings/local.py` at line 37, The same directory-creation
race condition fix applied in local settings should be mirrored in production
settings: update the LOG_DIR initialization in production.py to use the same
atomic mkdir approach with exist_ok=True instead of a check-then-create pattern.
Locate the LOG_DIR setup logic in the production settings module and make it
consistent with the local.py change so concurrent startup cannot fail there
either.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@apps/api/plane/settings/local.py`:
- Line 37: The same directory-creation race condition fix applied in local
settings should be mirrored in production settings: update the LOG_DIR
initialization in production.py to use the same atomic mkdir approach with
exist_ok=True instead of a check-then-create pattern. Locate the LOG_DIR setup
logic in the production settings module and make it consistent with the local.py
change so concurrent startup cannot fail there either.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c7a3355a-bb14-4022-a20c-c7bc4563e03a

📥 Commits

Reviewing files that changed from the base of the PR and between 7fbf14a and 0887f34.

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

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