Gå till innehållet

Common pitfalls

These took me a while to debug so read this so you don't have to go through the same problems.

  • pool deadlocks
    • pool with 2 connections
    • HTTP connection A aquires one connection
    • HTTP connection B aquires 1 connection
    • no connections left in pool
    • A tries to aquire another DB connection (e.g. by writing .fetch_one(&self.db) instead of using one transaction for the entire handler)
    • A waits forever because no connections are available
    • B also tries to get another connection (because it's running the same handler)
    • deadlock:(
    • solution: use ONE transaction per handler (incl. in helper functions)
  • service deadlocks
    • same as above but minilith talks to transactions
    • transaction has to complete callback before it returns
    • minilith callback handler waits for DB connection, never gets it because they're never freed because it's held over the HTTP request to transactions
    • deadlock:(
    • solution: don't hold DB connection over HTTP call! Reacquiring it after is OK. Also, don't await for the callback to complete before returning!