Skip to content

Commit

Permalink
Cleanup iRODS session directly, it is not guaranteed that __del__ is …
Browse files Browse the repository at this point in the history
…called.
  • Loading branch information
lwesterhof committed Jul 31, 2023
1 parent df9742d commit db048c3
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions connman.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ def __init__(self, sid: int, irods: iRODSSession) -> None:
self.irods_time: float = time.time() # iRODS session start time
self.lock: threading.Lock = threading.Lock()

def __del__(self) -> None:
self.irods.cleanup()
print(f"[gc/logout]: Cleanup session {self.sid}")


sessions: Dict[int, Session] = dict() # Custom session dict instead of Flask session (cannot pickle iRODS session)
lock: threading.Lock = threading.Lock()
Expand All @@ -42,15 +38,15 @@ def gc() -> None:
t = time.time()
global sessions

# Remove sessions that exceed the Flask session TTL.
sessions = {k: v for k, v in sessions.items() if t - v.time < TTL or v.lock.locked()}

# Cleanup iRODS sessions that exceed the iRODS session TTL.
for _, s in sessions.items():
if t - s.irods_time > IRODS_TTL and not s.lock.locked():
s.irods.cleanup()
s.irods_time = time.time()

# Remove sessions that exceed the Flask session TTL.
sessions = {k: v for k, v in sessions.items() if t - v.time < TTL or v.lock.locked()}

time.sleep(1)


Expand Down Expand Up @@ -104,7 +100,10 @@ def clean(sid: int) -> None:
"""
global sessions
if sid in sessions:
s: Session = sessions[sid]
s.irods.cleanup()
del sessions[sid]
print(f"[logout]: Cleanup session {sid}")


def extend(sid: int) -> None:
Expand Down

0 comments on commit db048c3

Please sign in to comment.