Skip to content

perf: replace blocking urllib webhook with async httpx + connection pooling (issue #193)#197

Merged
Elshayib merged 1 commit into
masterfrom
fix/issue-193-async-webhook
Jun 17, 2026
Merged

perf: replace blocking urllib webhook with async httpx + connection pooling (issue #193)#197
Elshayib merged 1 commit into
masterfrom
fix/issue-193-async-webhook

Conversation

@Elshayib

Copy link
Copy Markdown
Owner

Summary

Fixes #193. Replaces blocking urllib + run_in_executor webhook calls with httpx.AsyncClient for non-blocking async HTTP with connection pooling.

Changes

  • Added httpx>=0.28.0 to dependencies with mypy override
  • AlertManager.__init__: added _httpx_client field
  • AlertManager._get_client(): lazily creates a shared httpx.AsyncClient with connection pooling (20 max connections, 10 keepalive, 30s keepalive expiry)
  • AlertManager.close(): new method to properly close the httpx client
  • AlertManager._send_webhook(): replaced urllib.request.urlopen + loop.run_in_executor(None, ...) with await client.post(...) — fully non-blocking, no thread pool usage, connection reuse via keep-alive
  • RealtimeListener.stop(): now calls await self._alert_manager.close() to clean up the http client
  • Graceful fallback: if httpx is not installed, logs an error and returns immediately
  • hmac moved to module level import (was inside _send_webhook)
  • Tests updated: all 5 webhook tests now mock httpx.AsyncClient instead of urllib.request.urlopen; added test_send_webhook_skipped_when_httpx_unavailable

Test Results

  • 639/639 tests passing (5 webhook tests updated + 1 new)
  • ruff clean
  • mypy clean (source)

…ooling (issue #193)

- Add httpx>=0.28.0 to dependencies with mypy override
- Replace urllib + run_in_executor with httpx.AsyncClient using connection pooling (20 max connections, 10 keepalive, 30s keepalive expiry)
- Add AlertManager.close() to clean up the httpx client; call from RealtimeListener.stop()
- Move hmac import to module level (was inside _send_webhook)
- Add _HTTPX_AVAILABLE graceful fallback when httpx is not installed
- Update webhook tests to mock httpx.AsyncClient instead of urllib

Closes #193
@Elshayib Elshayib added bug Something isn't working performance labels Jun 17, 2026
@github-actions github-actions Bot added enhancement New feature or request security tests labels Jun 17, 2026
@Elshayib Elshayib merged commit 35acb06 into master Jun 17, 2026
6 checks passed
@Elshayib Elshayib deleted the fix/issue-193-async-webhook branch June 17, 2026 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request performance security tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace blocking urllib webhook calls with async HTTP client and connection pooling

1 participant