Skip to content

Guard the invalid session flag reset against a removed session - #492

Merged
LarsLaskowski merged 2 commits into
mainfrom
claude/issue-491-rue7ts
Jul 25, 2026
Merged

Guard the invalid session flag reset against a removed session#492
LarsLaskowski merged 2 commits into
mainfrom
claude/issue-491-rue7ts

Conversation

@LarsLaskowski

@LarsLaskowski LarsLaskowski commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Summary

ProcessPacket reset Session.IsInvalidSession directly after calling RemoveInvalidSessionFromDatabase, which sets Session to null as soon as the session row was deleted. On the successful removal path this threw a NullReferenceException. The flag is now reset before the removal, so removing an invalid session no longer produces an error.

Linked issues

Closes #491

Review notes

  • The exception was swallowed by the surrounding catch, logged as "Error processing packet {PacketType}!" and written to LastError, which hid the real reason and skipped the remaining work inside the if (processor != null) block.
  • Resetting the flag before the removal was chosen over a null check afterwards: RepositoryBase.Remove also reports success when no row matched, so the session is cleared on every reachable path and a guarded reset would add a condition that no test can cover. The behaviour for a failed removal is unchanged, the flag is cleared either way.
  • The new PacketProcessorInvalidSessionTests drives a session start event, a session packet and a participants packet with a team id of 41 through a packet processor with UseDatabase = true. It rewrites the unique session id of the sample packets so the test works on its own database session and does not interfere with the shared test data. The test fails with a NullReferenceException in LastError without the fix.

claude added 2 commits July 25, 2026 16:28
RemoveInvalidSessionFromDatabase clears the runtime session as soon as the
session row was deleted, so the following reset of IsInvalidSession threw a
NullReferenceException on exactly the successful path. The exception was
swallowed by the surrounding catch and logged as a packet processing error,
which hid the real reason and skipped the remaining work in ProcessPacket.
A regression test drives a participants packet of an online session through
the packet processor with database usage to cover the removal path.
The null-conditional reset after the removal added a branch that cannot be
reached by a test, because Remove also reports success when no row matched,
so the session is always cleared on that path. SonarCloud therefore failed
the quality gate with 66.7% coverage on new code. Resetting the flag before
the removal keeps the original intent for a failed removal without adding an
untestable condition.
@sonarqubecloud

Copy link
Copy Markdown

@LarsLaskowski
LarsLaskowski merged commit 0fc2ba1 into main Jul 25, 2026
6 checks passed
@LarsLaskowski
LarsLaskowski deleted the claude/issue-491-rue7ts branch July 25, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullReferenceException after an invalid session was removed in PacketProcessor

2 participants