Title: Django Server Hangs During Startup/Shutdown Due to Blocking LogtailHandler.flush() · Issue #35 · logtail/logtail-python · GitHub
Open Graph Title: Django Server Hangs During Startup/Shutdown Due to Blocking LogtailHandler.flush() · Issue #35 · logtail/logtail-python
X Title: Django Server Hangs During Startup/Shutdown Due to Blocking LogtailHandler.flush() · Issue #35 · logtail/logtail-python
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 ...
Open Graph 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...
X 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...
Opengraph URL: https://github.com/logtail/logtail-python/issues/35
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Django Server Hangs During Startup/Shutdown Due to Blocking LogtailHandler.flush()","articleBody":"\n## Problem\n\nDjango 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.\n\n## Root Cause\n\nThe `LogtailHandler.flush()` method blocks indefinitely in an infinite loop without timeout:\n\n```python\n# logtail/flusher.py lines 80-84\ndef flush(self):\n self._flushing = True\n while not self._clean or not self.pipe.empty():\n time.sleep(self.check_interval) # Infinite loop!\n self._flushing = False\n```\n\n## Reproduction\n\n1. Add LogtailHandler to Django logging configuration\n2. Start Django server: `python manage.py runserver`\n3. Stop server with Ctrl+C\n4. **Result**: Server hangs and must be force-killed\n\n**Workaround**: Commenting out logtail handler makes Django work normally.\n\n## Error When Force-Interrupted\n\n```\nTraceback (most recent call last):\n File \"/usr/lib/python3.11/logging/__init__.py\", line 2185, in shutdown\n h.flush()\n File \"logtail/flusher.py\", line 83, in flush\n time.sleep(self.check_interval)\nKeyboardInterrupt:\n```\n\n## Environment\n- Python 3.11, Django 3.2.8+, logtail 0.3.3\n\n## Proposed Fix\n\nAdd a `flush_timeout` parameter (default 5 seconds) to prevent infinite waiting:\n\n```python\ndef flush(self):\n self._flushing = True\n start_time = time.time()\n while not self._clean or not self.pipe.empty():\n if time.time() - start_time > self.flush_timeout:\n break # Exit after timeout\n time.sleep(self.check_interval)\n self._flushing = False\n```\n\n## Impact\n\n- Prevents graceful Django shutdown\n- Affects development workflow and deployment scripts\n- Forces developers to kill processes manually\n","author":{"url":"https://github.com/vikram-typeset","@type":"Person","name":"vikram-typeset"},"datePublished":"2025-09-22T09:04:09Z","url":"https://github.com/logtail/logtail-python/issues/35"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:46ef5d4d-4ea1-da7f-158d-128d6e832f79 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EB9A:1B1794:1AED4C:23A13B:6AFBB257 |
| html-safe-nonce | 1eab4b221cad51458fd0c66fbad8d2a01f3a61bd2a31c7f86196d7a088f7ee24 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjlBOjFCMTc5NDoxQUVENEM6MjNBMTNCOjZBRkJCMjU3IiwidmlzaXRvcl9pZCI6IjQzNDA3MzczODEyODg4ODI3NzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | abe8068638d59c7d7aba4bc05fc030702827c494a67667f18e31e94b9bd566e2 |
| hovercard-subject-tag | issue:3439887864 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/logtail/logtail-python/35/issue_layout |
| twitter:image | https://opengraph.githubassets.com/180243d362eba06fe87ee89ba67efa82da6f417efba1871648ee3750c4e51cd4/logtail/logtail-python/issues/35 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/180243d362eba06fe87ee89ba67efa82da6f417efba1871648ee3750c4e51cd4/logtail/logtail-python/issues/35 |
| og:image:alt | 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vikram-typeset |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2b2ef9c1578c18d8ed27027940544c958743213cf4461659f14d3ccdf51e162c |
| turbo-cache-control | no-preview |
| go-import | github.com/logtail/logtail-python git https://github.com/logtail/logtail-python.git |
| octolytics-dimension-user_id | 78922349 |
| octolytics-dimension-user_login | logtail |
| octolytics-dimension-repository_id | 351343852 |
| octolytics-dimension-repository_nwo | logtail/logtail-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 351343852 |
| octolytics-dimension-repository_network_root_nwo | logtail/logtail-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e4cce0e99cf61481a318ff12c2e8580153a6c7c6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width