Skip to content

Handle concurrent stale socket cleanup#669

Draft
teta2k wants to merge 1 commit into
mainfrom
fix-background-process-socket-race
Draft

Handle concurrent stale socket cleanup#669
teta2k wants to merge 1 commit into
mainfrom
fix-background-process-socket-race

Conversation

@teta2k

@teta2k teta2k commented Jul 22, 2026

Copy link
Copy Markdown

What changed

  • Tolerate FileNotFoundError when removing a stale Unix-domain socket.
  • Add a regression test covering another application worker winning the cleanup race.

Why

Multiple Gunicorn workers can call start_background_process() concurrently. They may both observe the stale socket and determine that no background process is active, after which the first worker removes the socket and the second worker raises FileNotFoundError. Because this happens while the application is loading, the affected Gunicorn worker fails to boot.

The background process listener is already exclusive and makes any duplicate process attempt exit cleanly, so treating an already-removed stale socket as successful cleanup is sufficient.

Impact

Concurrent worker startup no longer fails because another worker removed the stale IPC socket first.

Validation

  • Focused background-process tests: 4 passed
  • Background-process test area: 160 passed; 3 integration tests require the repository's local HTTP test server on port 5050
  • Black: passed
  • Pylint: 10.00/10

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