Skip to content

Fix race condition causing NullReferenceException in LifecycleViewController#104

Merged
jodavis merged 2 commits intodev/jodavis/ADR-128-spec-programmable-ir-commandsfrom
copilot/sub-pr-96
Feb 27, 2026
Merged

Fix race condition causing NullReferenceException in LifecycleViewController#104
jodavis merged 2 commits intodev/jodavis/ADR-128-spec-programmable-ir-commandsfrom
copilot/sub-pr-96

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

Sporadic NullReferenceException in UpdateTaskName() during parallel service initialization, caused by Activity.Dispose() mutating _activities without holding _lock while LINQ iterates it under the lock.

List<T>.RemoveAt() zeros freed slots to null; a concurrent LINQ iterator could observe these null slots, causing x => x.FatalError is not null to throw.

Fix

  • Activity.Dispose() now wraps _activities.Remove(this) in lock (_owner._lock), consistent with how StartTask already protects Insert
// Before
public void Dispose()
{
    if (FatalError is null)
        _owner._activities.Remove(this);  // unprotected — races with UpdateTaskName
    _owner.UpdateTaskName();
}

// After
public void Dispose()
{
    lock (_owner._lock)
    {
        if (FatalError is null)
            _owner._activities.Remove(this);
    }
    _owner.UpdateTaskName();
}

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…Activity.Dispose

Co-authored-by: jodavis <6740581+jodavis@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix flakiness in end to end tests for Programmable IR Commands Fix race condition causing NullReferenceException in LifecycleViewController Feb 27, 2026
@jodavis jodavis marked this pull request as ready for review February 27, 2026 13:20
@jodavis jodavis merged commit b2b4b54 into dev/jodavis/ADR-128-spec-programmable-ir-commands Feb 27, 2026
jodavis added a commit that referenced this pull request Feb 27, 2026
…troller (#104)

* Fix NullReferenceException race condition in LifecycleViewController.Activity.Dispose

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jodavis <6740581+jodavis@users.noreply.github.com>
jodavis added a commit that referenced this pull request Mar 11, 2026
…troller (#104)

* Fix NullReferenceException race condition in LifecycleViewController.Activity.Dispose

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jodavis <6740581+jodavis@users.noreply.github.com>
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.

2 participants