mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-07-06 03:51:14 +03:00
drop stale shm cache refs when cached segment is too small for requested shape
This commit is contained in:
parent
c2c5c9496e
commit
1ceacd71e3
@ -1089,10 +1089,32 @@ class SharedMemoryFrameManager(FrameManager):
|
|||||||
|
|
||||||
def get(self, name: str, shape) -> Optional[np.ndarray]:
|
def get(self, name: str, shape) -> Optional[np.ndarray]:
|
||||||
try:
|
try:
|
||||||
if name in self.shm_store:
|
required = int(np.prod(shape))
|
||||||
shm = self.shm_store[name]
|
shm = self.shm_store.get(name)
|
||||||
else:
|
if shm is not None and shm.size < required:
|
||||||
|
# Cached reference points at an older, smaller segment
|
||||||
|
# that was unlinked and recreated at a larger size in a
|
||||||
|
# camera add/remove cycle. Drop the stale ref so we
|
||||||
|
# reopen the current segment.
|
||||||
|
try:
|
||||||
|
shm.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
self.shm_store.pop(name, None)
|
||||||
|
shm = None
|
||||||
|
if shm is None:
|
||||||
shm = UntrackedSharedMemory(name=name)
|
shm = UntrackedSharedMemory(name=name)
|
||||||
|
if shm.size < required:
|
||||||
|
# Transient mid-recreate state: the OS-level segment
|
||||||
|
# is still at the previous (smaller) size because the
|
||||||
|
# maintainer hasn't allocated the new one yet. Don't
|
||||||
|
# cache it (so the next call re-opens once the
|
||||||
|
# maintainer has caught up) and skip this frame.
|
||||||
|
try:
|
||||||
|
shm.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return None
|
||||||
self.shm_store[name] = shm
|
self.shm_store[name] = shm
|
||||||
return np.ndarray(shape, dtype=np.uint8, buffer=shm.buf)
|
return np.ndarray(shape, dtype=np.uint8, buffer=shm.buf)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user