Commit a576d10
committed
fix(capsule): one transient error no longer permanently kills the audit trail
CapsuleStorage._ensure_db assigned self._engine BEFORE running create_all, and
gated re-entry on `if self._engine is None`. So any failure inside create_all (a
locked db file, a full disk, an engine pool bound to a since-closed event loop)
left the instance holding an engine but no session factory. Every later call then
short-circuited, did nothing, and _get_session_factory() raised "Database not
initialized -- call _ensure_db() first" for the entire life of the process, while
_ensure_db() was in fact being called every time. One transient error silently
and permanently disabled capsule persistence, and the error message actively
misled whoever read it.
Under "Capsule everything" (Trust Foundation layer 5, the immutable audit trail),
a silently dead audit log is a security failure, not an availability one.
Initialization is now atomic. Readiness keys off _session_factory, which is what
callers actually need; the engine and the factory publish together and only after
create_all succeeds; a failure disposes the partial engine and leaves both unset,
so the next call retries from scratch. A concurrent initializer is handled by
keeping theirs and disposing ours rather than leaking an engine.1 parent 68ddbe0 commit a576d10
1 file changed
Lines changed: 50 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
117 | 125 | | |
118 | | - | |
119 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
120 | 132 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
126 | 160 | | |
127 | 161 | | |
128 | 162 | | |
| |||
0 commit comments