-
Notifications
You must be signed in to change notification settings - Fork 12
Closed
Description
Problem
Django server hangs indefinitely during startup/shutdown when LogtailHandler is enabled. When commenting out the logtail configuration, the server works fine. This issue occurs consistently but not always - depends on timing and network conditions.
Root Cause
The LogtailHandler.flush() method blocks indefinitely in an infinite loop without timeout:
# logtail/flusher.py lines 80-84
def flush(self):
self._flushing = True
while not self._clean or not self.pipe.empty():
time.sleep(self.check_interval) # Infinite loop!
self._flushing = FalseReproduction
- Add LogtailHandler to Django logging configuration
- Start Django server:
python manage.py runserver - Stop server with Ctrl+C
- Result: Server hangs and must be force-killed
Workaround: Commenting out logtail handler makes Django work normally.
Error When Force-Interrupted
Traceback (most recent call last):
File "/usr/lib/python3.11/logging/__init__.py", line 2185, in shutdown
h.flush()
File "logtail/flusher.py", line 83, in flush
time.sleep(self.check_interval)
KeyboardInterrupt:
Environment
- Python 3.11, Django 3.2.8+, logtail 0.3.3
Proposed Fix
Add a flush_timeout parameter (default 5 seconds) to prevent infinite waiting:
def flush(self):
self._flushing = True
start_time = time.time()
while not self._clean or not self.pipe.empty():
if time.time() - start_time > self.flush_timeout:
break # Exit after timeout
time.sleep(self.check_interval)
self._flushing = FalseImpact
- Prevents graceful Django shutdown
- Affects development workflow and deployment scripts
- Forces developers to kill processes manually
Metadata
Metadata
Assignees
Labels
No labels