Skip to content

fix: stop the WaitFor timer when the first check passes before it is … - #1956

Open
xaviergxf wants to merge 1 commit into
bUnit-dev:mainfrom
xaviergxf:fix/waitfor-timer-leak
Open

xaviergxf wants to merge 1 commit into
bUnit-dev:mainfrom
xaviergxf:fix/waitfor-timer-leak

Conversation

@xaviergxf

@xaviergxf xaviergxf commented Oct 23, 2026 •

Copy link
Copy Markdown

There is a memory leak that this PR fixes.

@xaviergxf
xaviergxf force-pushed the fix/waitfor-timer-leak branch 2 times, most recently from e92c550 to b93370f Compare October 23, 2026 14:35
…started

When a WaitFor* check passes synchronously, the helper disposes itself from
inside the constructor, while the timer field is still null. The constructor
then looks at WaitTask.IsCompleted to decide whether to start the timer, but
WaitTask is a WhenAny(...).Unwrap() that completes on the thread pool, so it
usually still reads as not completed at that point and the timer is started
anyway. The later Dispose() from the using block returns early because the
helper is already disposed, and nothing ever stops the timer.

The timer's state is the helper, so until the timeout elapses it roots the
helper, the rendered component, the renderer and everything the renderer
holds. With bUnit's default timeout of one second that goes unnoticed. With a
long DefaultWaitTimeout, a test suite keeps every page it rendered in memory
for its whole run.

The constructor now also checks isDisposed before starting the timer, and
disposes the timer right after creating it if the check disposed the helper in
between.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@xaviergxf
xaviergxf force-pushed the fix/waitfor-timer-leak branch from b93370f to f80e973 Compare October 23, 2026 14:36

This branch has not been deployed

No deployments
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.

1 participant