Commit aa848ce
authored
fix: reject heartbeats on lock timeout instead of proceeding unsafely (#159)
* fix: reject heartbeats when lock times out instead of proceeding unsafely
When the heartbeat lock couldn't be acquired within 1s, the code would
proceed without the lock (causing concurrent SQLite access and "database
is locked" errors) then try to release a lock it didn't own.
Now returns 503 so the client can retry cleanly. Also increased timeout
to 10s to reduce spurious rejections.
* fix: make heartbeat lock a class variable for actual thread safety
The lock was created in __init__ as self.lock = Lock(), but Flask-RESTX
instantiates Resource per-request, so each request got its own lock
providing zero mutual exclusion. Moving to a class variable ensures all
heartbeat requests are properly serialized.1 parent 153e7fd commit aa848ce
1 file changed
Lines changed: 9 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
274 | 279 | | |
275 | | - | |
276 | 280 | | |
277 | 281 | | |
278 | 282 | | |
| |||
291 | 295 | | |
292 | 296 | | |
293 | 297 | | |
294 | | - | |
295 | | - | |
| 298 | + | |
| 299 | + | |
296 | 300 | | |
297 | | - | |
| 301 | + | |
298 | 302 | | |
| 303 | + | |
299 | 304 | | |
300 | 305 | | |
301 | 306 | | |
| |||
0 commit comments