asgi-gzip 0.3 fixes a critical bug that broke Server-Sent Events (SSE) in production Datasette deployments. The middleware incorrectly compressed text/event-stream responses, causing browsers to drop connections. Developers deploying SSE features hit failures on instances running datasette-gzip, which depends on asgi-gzip.
This release ports Starlette’s fix, which excludes SSE content types from compression. Starlette, a core ASGI toolkit behind FastAPI, dropped the standalone middleware years ago but continues to maintain the logic internally. asgi-gzip, extracted for broader reuse, lagged behind due to a broken GitHub Actions workflow.
The Bug and Its Impact
SSE pushes real-time updates from server to client using HTTP chunked transfer encoding. Browsers like Chrome expect uncompressed text/event-stream streams; gzip mangles this, triggering resets after a few events. In Datasette—a tool that exposes SQLite databases as queryable web apps—this broke new features relying on live updates.
Datasette author Simon Willison encountered this during a production rollout. His instance used datasette-gzip (last updated 2021), pulling in asgi-gzip 0.2.1. The chain failed silently: no errors in logs, just dead streams. Production meant real users saw stalled updates, eroding trust in real-time capabilities.
Numbers tell the story. Datasette powers over 1,000 public instances (per its directory). SSE usage grows for plugins like datasette-realtime, which streams query changes. Unfixed, this bug stalls adoption of async features in resource-constrained environments where gzip saves bandwidth.
Why Maintenance Broke—and Lessons
asgi-gzip’s GitHub Actions included a cron job scanning Starlette for compression changes. It stopped running around mid-2023, missing Starlette’s October 2022 commit excluding text/event-stream and text/event-stream;charset=utf-8. Manual triggers by Willison integrated the patch, bumping to 0.3.0 on PyPI with 12 downloads in the first day.
This exposes open-source fragility. Extracted libraries like asgi-gzip (1.4k stars, 10 contributors) promise independence but risk drift. Starlette evolves fast—version 0.37.2 as of now—while forks depend on volunteers. datasette-gzip, orphaned since 2021, amplifies the issue: transitive deps compound staleness.
Check your stack: pip show asgi-gzip reveals versions. If below 0.3, SSE breaks under gzip. Production ASGI apps (Uvicorn, Hypercorn) hit 10-20% bandwidth savings from gzip, but at SSE’s cost. Test with curl:
curl -H 'Accept-Encoding: gzip' -N http://your-sse-endpoint
Decompress to verify.
Implications for ASGI Developers
Upgrade now: pip install asgi-gzip==0.3.0 or datasette-gzip (which auto-upgrades). This matters for FastAPI users rolling their own middleware—many copy-paste Starlette’s gzip code. Production savings justify it: 70% reduction on text payloads per Cloudflare stats.
Skeptically, standalone middleware trades convenience for risk. Starlette apps get fixes automatically; extracts don’t. Consider baking gzip into your app or using Mangum/Starlette directly. For Datasette, this unblocks SSE in facets, plugins, and actor streams—key for live dashboards.
Broader: GitHub Actions cron failures are common—5-10% flake rate per GitHub reports. Monitor with workflow_run events or Dependabot. Open-source sustainability hinges on this; one stalled job broke real prod deploys.
Bottom line: Patch your deps. SSE reliability underpins modern web apps, from chats to metrics. Ignore at your peril—users notice broken streams first.