Skip to content

Start the live session timer only once and dispose it safely - #489

Merged
LarsLaskowski merged 1 commit into
mainfrom
claude/issue-197-33pk9q
Jul 25, 2026
Merged

Start the live session timer only once and dispose it safely#489
LarsLaskowski merged 1 commit into
mainfrom
claude/issue-197-33pk9q

Conversation

@LarsLaskowski

@LarsLaskowski LarsLaskowski commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Summary

TimerManager.PrepareTimer created a new Timer and AutoResetEvent on every call and replaced the previous instances without disposing them. Because TimerManager is registered as a singleton and LiveSessionController.Get calls PrepareTimer, concurrent requests could leak timers and wait handles and start several timers in parallel.

The timer state is now guarded by a lock, so repeated or concurrent calls are ignored while a timer is running. Dispose releases the timer and the reset event exactly once, clears the action, resets IsTimerStarted and is safe to call multiple times; PrepareTimer on a disposed manager throws ObjectDisposedException. The due time and period were moved into named constants.

Linked issues

Closes #197

Review notes

The start guard lives inside TimerManager, so the existing IsTimerStarted check in LiveSessionController stays a fast path only and the controller was not changed. New MSTest coverage in F1Server.Tests/WebApi/TimerManagerTests.cs verifies the single start behaviour, the concurrent start path, the tick rate after repeated calls, and the disposal behaviour.

PrepareTimer created a new Timer and AutoResetEvent on every call and replaced the previous instances without disposing them, leaking handles on the singleton TimerManager. The timer state is now guarded by a lock, repeated calls are ignored while a timer is running, and Dispose releases the resources once and resets the started state. Calling PrepareTimer on a disposed manager now throws ObjectDisposedException.
@sonarqubecloud

Copy link
Copy Markdown

@LarsLaskowski
LarsLaskowski merged commit 3b259c4 into main Jul 25, 2026
6 checks passed
@LarsLaskowski
LarsLaskowski deleted the claude/issue-197-33pk9q branch July 25, 2026 15:40
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.

F-277 · PrepareTimer is executed on each call from LiveSessionController (LiveSessionController.cs:58) and overwrites …

2 participants