Log inBook a Demo
BuildSeniorBackendAuto-graded

Fix a pool that leaks database connections

Make a connection pool open a bounded set of connections, reuse them, and refuse checkouts when all are in use.pool.py is meant to hand out a small, capped set of reusable database connections. In production the open-connection count goes up with every request and never drops, so the service leaks file descriptors and floods the database with new connections. Bring ConnectionPool in line with SPEC.md.
45 min
python

You're done when

  • When every connection is checked out, acquire() raises PoolExhausted and doesn't open a new one.
  • After a connection is released, the next acquire() hands back that same connection.
  • with pool.connection() releases the connection when the block ends, even if the block raises.

What it measures

Back-end developmentStopping at `size` connections and raising `PoolExhausted` once they're all in use.
Performance optimizationWhether connections get reused, so a busy service stops opening a new one per request.
Resource lifecycle disciplineReturning a connection to the pool on every way out of a `with` block, including errors.

Your environment

Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish

Start this lab

45 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo