mirror of
https://github.com/frappe/gunicorn.git
synced 2026-07-03 03:01:31 +08:00
Add a timeout when waiting for initial request data in worker threads. If no data arrives within 5 seconds, the connection is deferred back to the main poller instead of blocking the thread indefinitely. This fixes a regression from v24 where connections were submitted directly to the thread pool after accept(). In v23, connections were registered with the poller first and only submitted when data arrived. The new hybrid approach maintains the performance benefits for fast clients (immediate processing) while protecting against slow-client scenarios that can exhaust the thread pool and cause health check timeouts. Changes: - Add _DEFER sentinel and DEFAULT_WORKER_DATA_TIMEOUT constant - Add TConn.wait_for_data() method using selectors - Add TConn.data_ready flag to track data availability - Add pending_conns deque for deferred connections - Add on_pending_socket_readable() callback - Add murder_pending() to clean up timed-out pending connections - Modify handle() to wait for data with timeout before processing - Modify finish_request() to handle _DEFER and register with poller Fixes #3518
Gunicorn
Gunicorn is maintained by volunteers. If it powers your production, please consider supporting us:
Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX. It's a pre-fork worker model ported from Ruby's Unicorn project. The Gunicorn server is broadly compatible with various web frameworks, simply implemented, light on server resource usage, and fairly speedy.
New in v25: Per-app worker allocation for dirty arbiters, HTTP/2 support (beta)!
Quick Start
pip install gunicorn
gunicorn myapp:app --workers 4
For ASGI applications (FastAPI, Starlette):
gunicorn myapp:app --worker-class asgi
Features
- WSGI support for Django, Flask, Pyramid, and any WSGI framework
- ASGI support for FastAPI, Starlette, Quart
- HTTP/2 support (beta) with multiplexed streams
- Dirty Arbiters (beta) for heavy workloads (ML models, long-running tasks)
- uWSGI binary protocol for nginx integration
- Multiple worker types: sync, gthread, gevent, eventlet, asgi
- Graceful worker process management
- Compatible with Python 3.9+
Documentation
Full documentation at https://gunicorn.org
Community
- Report bugs on GitHub Issues
- Chat in #gunicorn on Libera.chat
- See CONTRIBUTING.md for contribution guidelines
Support
Powering Python apps since 2010. Support continued development.
License
Gunicorn is released under the MIT License. See the LICENSE file for details.
Languages
Python
99.9%