Skip to content

fix: leave Granian backpressure at its default - #82

Merged
lesnik512 merged 1 commit into
mainfrom
drop-granian-backpressure
Oct 22, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
drop-granian-backpressure

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Same change as modern-python/fastapi-sqlalchemy-template#105. Reverts the backpressure half of #77.

Granian's backpressure limits open connections per worker, not requests in flight. Each worker takes a semaphore permit before accept() and releases it when the TCP connection closes (granian v2.8.3, src/workers.rs lines 704 and 1074). An idle keep-alive connection holds its permit, so with backpressure set to the pool size (5 by default) a reverse proxy that keeps upstream connections open can take every slot by itself. New connections then wait in the backlog until Granian drops an idle one at --http1-header-read-timeout, 30 s by default, even when the app is doing nothing.

Reproduced locally with backpressure=2, two idle HTTP/1.1 keep-alive clients, and then a third request:

Granian settings third request served after
--backpressure 2 30.0 s
--backpressure 2 --http1-header-read-timeout 5000 5.0 s
default backpressure 0.0 s

Changes

  • app/__main__.py no longer passes backpressure, so Granian uses its default (backlog / workers).
  • test_main asserts that backpressure is not passed.
  • AGENTS.md: the pool sizing paragraph says why backpressure stays at its default.

Overload is still bounded. A request that finds the pool empty waits for a connection, and after DB_POOL_TIMEOUT it gets a 503 from database_unavailable_handler. The 30 s default for that timeout is unchanged here. Lowering it would shed load sooner, and that is a separate decision.

Testing

just test: 87 passed, 100% coverage. ruff format --check and ruff check are clean. ty check runs in CI, because the dev environment does not install on macOS (pyroscope-io fails to build).

@lesnik512
lesnik512 merged commit 97efe13 into main Oct 22, 2026
3 checks passed
@lesnik512
lesnik512 deleted the drop-granian-backpressure branch October 22, 2026 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant