Skip to content

Commit

Permalink
fix(storage): auto-close storage on session timeout
Browse files Browse the repository at this point in the history
Do not leave the shared storage device opened if the owning session
has not interacted with us before the session timeout expired.

Signed-off-by: Cedric Hombourger <[email protected]>
  • Loading branch information
chombourger committed Dec 29, 2024
1 parent 0e70d39 commit c2ee066
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions mtda/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class STORAGE:
LOCKED = "LOCKED"
UNLOCKED = "UNLOCKED"
OPENED = "OPENED"
CORRUPTED = "CORRUPTED"
UNKNOWN = "???"
RETRY_INTERVAL = 0.5
TIMEOUT = 30
Expand Down
12 changes: 12 additions & 0 deletions mtda/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,18 @@ def session_event(self, info):
# There are active sessions: reset power expiry
self._power_expiry = None

elif event == CONSTS.SESSION.INACTIVE:
# If a session had the shared storage device opened but has gone
# quiet, close it to let others grab it. Let's assume that its
# content is corrupted: send a storage event that UIs may use to
# display a warning
session = info[1]
if self._storage_opened is True and self._storage_owner == session:
self.mtda.debug(2, "closing storage for idle session "
f"{session}, storage may be corrupted!")
self._storage_event(CONSTS.STORAGE.CORRUPTED)
self.storage_close(None)

def _session_check(self, session=None):
self.mtda.debug(3, f"main._session_check({session})")

Expand Down

0 comments on commit c2ee066

Please sign in to comment.