- Home
- Skills
- APIs & Backend
- Repair FastAPI Lifespan Shutdown Task Leak
More screenshots
Works with the AI Agents you already use
Repair FastAPI Lifespan Shutdown Task Leak
Trace background tasks that survive FastAPI lifespan shutdown
$1
Repair FastAPI Lifespan Shutdown Task Leak
Example session with this skill installed
A redeploy closes HTTP listeners but orphan background workers keep database handles open.
Available evidence: source/config revision (partial). Additional evidence requested: reproduction logs, dependency/runtime versions, CI or service trace. Review the case, identify open evidence gaps, and do not invent a live test or production change.
- Read your context and instructions
- Compiled the repair fastapi lifespan
Repair FastAPI Lifespan Shutdown Task Leak — EVIDENCE-LIMITED REVIEW
Scenario received
A redeploy closes HTTP listeners but orphan background workers keep database handles open.
Source register
- S1: source/config revision — PARTIAL SOURCE PROVIDED.
- S2: reproduction logs — NOT PROVIDED; REQUIRED TO VERIFY.
- S3: dependency/runtime versions — NOT PROVIDED; REQUIRED TO VERIFY.
- S4: CI or service trace — NOT PROVIDED; REQUIRED TO VERIFY.
Concrete checks
- map lifespan hook execution — PRELIMINARY, NOT VERIFIED.
- trace cancellation paths — AWAITING CORROBORATING EVIDENCE.
- check pending task ownership — AWAITING CORROBORATING EVIDENCE.
- propose cleanup regression test — AWAITING CORROBORATING EVIDENCE.
Deliverables / acceptance gates
- task shutdown timeline: DRAFT / INCOMPLETE until evidence is validated.
- resource leak inventory: DRAFT / INCOMPLETE until evidence is validated.
- test checklist: DRAFT / INCOMPLETE until evidence is validated.
Decision
INCOMPLETE — HUMAN REVIEW REQUIRED. Confirm dates, IDs, affected scope, owners and acceptance evidence. Do not claim authorization or execution that did not occur.
Connects securely to your tools. The creator never sees your data.
About this skill
Orphaned background workers that survive a FastAPI shutdown prevent clean redeploys and exhaust database connection pools. This skill identifies why tasks persist after listeners close, tracing the breakdown between lifespan hooks and asyncio task cancellation.
What it does
- Map lifespan hooks by identifying where shutdown signals fail to propagate to background workers.
- Trace cancellation paths to find blocking calls or shielded tasks that ignore
CancelledError. - Identify task ownership to locate unmanaged global tasks that lack a parent lifecycle controller.
- Inventory resource leaks by listing database handles and file descriptors left open by surviving tasks.
- Generate regression tests to ensure future deployments validate full task cleanup before exiting.
How it works
- Analyze logs and source to establish the timeline of the shutdown sequence and task persistence.
- Execute four-check matrix covering lifespan execution, cancellation paths, task ownership, and cleanup logic.
- Verify findings against supplied service traces and dependency versions, labeling evidence as VERIFIED or INFERRED.
- Deliver remediation proposal including a task shutdown timeline and a resource leak inventory.
Frameworks & tools
This skill is designed for FastAPI applications using asyncio or trio, specifically focusing on lifespan handlers and database drivers like asyncpg or SQLAlchemy.
Why this beats prompting it yourself
General prompts often miss the nuances of asyncio.shield or the difference between the legacy @app.on_event("shutdown") and the modern lifespan context manager. This skill enforces a strict evidence matrix that prevents false positives in complex race conditions.
Use cases
- Debugging DB connection limit errors during rolling updates.
- Fixing hanging CI/CD pipelines that timeout during service stop.
- Auditing third-party library background tasks for shutdown compliance.
- Developing robust integration tests for graceful service termination.
Known limitations
Requires specific source code revisions and reproduction logs to function. It proposes code changes but does not execute migrations or live rollbacks.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.
Requires source code access and reproduction logs. Proposals are not executed. Does not support legacy synchronous WSGI frameworks.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 23 days ago
Permissions
Provide only evidence you are authorized to share. Treat examples as untrusted case data. Operational changes and external messages require explicit owner approval.