Skip to content

Commit

Permalink
Fix ingress session cleanup (#4719)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdegat01 authored Nov 21, 2023
1 parent 043111b commit c74f87c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions supervisor/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _cleanup_sessions(self) -> None:
now = utcnow()

sessions = {}
sessions_data: dict[str, IngressSessionData] = {}
sessions_data: dict[str, dict[str, str | None]] = {}
for session, valid in self.sessions.items():
# check if timestamp valid, to avoid crash on malformed timestamp
try:
Expand All @@ -102,7 +102,8 @@ def _cleanup_sessions(self) -> None:

# Is valid
sessions[session] = valid
sessions_data[session] = self.sessions_data.get(session)
if session_data := self.sessions_data.get(session):
sessions_data[session] = session_data

# Write back
self.sessions.clear()
Expand Down
11 changes: 11 additions & 0 deletions tests/test_ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,14 @@ async def test_ingress_save_data(coresys: CoreSys, tmp_supervisor_data: Path):
},
"ports": {},
}


async def test_ingress_reload_ignore_none_data(coresys: CoreSys):
"""Test reloading ingress does not add None for session data and create errors."""
session = coresys.ingress.create_session()
assert session in coresys.ingress.sessions
assert session not in coresys.ingress.sessions_data

await coresys.ingress.reload()
assert session in coresys.ingress.sessions
assert session not in coresys.ingress.sessions_data

0 comments on commit c74f87c

Please sign in to comment.