Bird
0
0

What will happen if you forget to call await database.disconnect() in the FastAPI shutdown event when using the databases library?

medium📝 component behavior Q5 of 15
FastAPI - Database Integration
What will happen if you forget to call await database.disconnect() in the FastAPI shutdown event when using the databases library?
AThe database connection remains open, possibly causing resource leaks
BFastAPI will automatically disconnect the database
CThe application will crash immediately on shutdown
DThe database connection will close but raise a warning
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of disconnect in shutdown

    Calling await database.disconnect() properly closes the connection to avoid resource leaks.
  2. Step 2: Consequence of missing disconnect

    If disconnect is not called, the connection stays open, which can cause resource exhaustion or errors later.
  3. Final Answer:

    Database connection remains open, causing resource leaks -> Option A
  4. Quick Check:

    Missing disconnect = resource leak risk = C [OK]
Quick Trick: Always disconnect DB on shutdown to free resources [OK]
Common Mistakes:
MISTAKES
  • Assuming FastAPI auto disconnects DB
  • Expecting immediate crash on missing disconnect
  • Thinking disconnect raises warnings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes