Skip to main content

Async Callback Lifetime Pattern

Context​

Bare this captures in Drogon async callbacks and lock-free cross-thread access were the main source of historical defects (11 audit findings).

Decision​

Any object carrying async callbacks uses enable_shared_from_this; lambdas capture self/weak_ptr and bare this is forbidden (as are coroutines); initialization uses Meyers Singleton / call_once to eliminate SIOF; the thread safety of drogon::CacheMap's own mutex is acknowledged and relied upon (the EventLoop* only drives expiring timers and does no loop orchestration); look-aside cache stampedes are accepted as non-linearizable consistency.

Consequences and Current State​

This discipline is codified in db-operations.md (maintainer-facing rule source) as a project iron rule; all 11 concurrency-audit defects have been fixed with regression tests.