Skip to content

Fix gunicorn worker crashes on macOS#2839

Merged
crivetimihai merged 2 commits intomainfrom
fix-mac-crash
Feb 11, 2026
Merged

Fix gunicorn worker crashes on macOS#2839
crivetimihai merged 2 commits intomainfrom
fix-mac-crash

Conversation

@madhav165
Copy link
Copy Markdown
Collaborator

@madhav165 madhav165 commented Feb 11, 2026

🐛 Bug-fix PR

Fixes #2837


Summary

Disables gunicorn's --preload option by default on macOS to prevent worker processes from crashing with SIGSEGV errors.

Problem

On macOS, running make serve causes gunicorn workers to crash immediately after spawning:

[2026-02-11 14:07:39 +0530] [55715] [WARNING] Worker (pid:55773) was sent SIGSEGV!

This happens because macOS has strict fork-safety requirements. When --preload is used, the application code (including SQLAlchemy and asyncio) is loaded in the master process before workers are forked. The forked workers inherit invalid state and crash when trying to use these libraries.

Changes

gunicorn.config.py

  • Import platform module
  • Set preload_app = platform.system() != "Darwin" to disable preload on macOS
  • Add explicit worker_class = "uvicorn.workers.UvicornWorker" configuration

run-gunicorn.sh

  • Detect macOS via uname -s check
  • Set GUNICORN_PRELOAD_APP=false by default on macOS
  • Keep GUNICORN_PRELOAD_APP=true default on Linux and other platforms

Testing

  • Tested on macOS with make serve - workers spawn and stay running
  • Verified --preload flag is not passed on macOS
  • Verified Preload App: false shown in startup logs on macOS
  • Linux behavior unchanged (preload still enabled by default)

Backwards Compatibility

  • Users can override with GUNICORN_PRELOAD_APP=true if they need preload on macOS
  • Linux and other platforms unaffected
  • No changes to application code

🧪 Verification

Check Command Status
Lint suite make lint pass
Unit tests make test pass

📐 MCP Compliance (if relevant)

  • Matches current MCP spec
  • No breaking change to MCP clients

✅ Checklist

  • Code formatted (make black isort pre-commit)
  • No secrets/credentials committed

@madhav165 madhav165 added the bug Something isn't working label Feb 11, 2026
kevalmahajan
kevalmahajan previously approved these changes Feb 11, 2026
Copy link
Copy Markdown
Member

@kevalmahajan kevalmahajan left a comment

Choose a reason for hiding this comment

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

Tested on mac OS, works as expected.

madhav165 and others added 2 commits February 11, 2026 11:13
On macOS, gunicorn's preload feature causes SIGSEGV crashes when using
uvicorn workers with async libraries (SQLAlchemy, asyncio). This is due
to macOS's strict fork-safety requirements.

Changes:
- Disable preload_app by default on macOS in both config and shell script
- Users can override with GUNICORN_PRELOAD_APP=true if needed

Refs: benoitc/gunicorn#2761
Closes #2837
Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
@crivetimihai crivetimihai merged commit 2fb68ce into main Feb 11, 2026
48 checks passed
@crivetimihai crivetimihai deleted the fix-mac-crash branch February 11, 2026 11:14
ja8zyjits pushed a commit that referenced this pull request Feb 13, 2026
* fix: disable preload on macOS to prevent worker SIGSEGV crashes

On macOS, gunicorn's preload feature causes SIGSEGV crashes when using
uvicorn workers with async libraries (SQLAlchemy, asyncio). This is due
to macOS's strict fork-safety requirements.

Changes:
- Disable preload_app by default on macOS in both config and shell script
- Users can override with GUNICORN_PRELOAD_APP=true if needed

Refs: benoitc/gunicorn#2761
Closes #2837
Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>

* lint

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

---------

Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
kcostell06 pushed a commit to kcostell06/mcp-context-forge that referenced this pull request Feb 24, 2026
* fix: disable preload on macOS to prevent worker SIGSEGV crashes

On macOS, gunicorn's preload feature causes SIGSEGV crashes when using
uvicorn workers with async libraries (SQLAlchemy, asyncio). This is due
to macOS's strict fork-safety requirements.

Changes:
- Disable preload_app by default on macOS in both config and shell script
- Users can override with GUNICORN_PRELOAD_APP=true if needed

Refs: benoitc/gunicorn#2761
Closes IBM#2837
Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>

* lint

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

---------

Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: gunicorn workers crash with SIGSEGV on macOS when running make serve

3 participants