Skip to content

Fix for 4280 interaction async handler scheduling#4351

Merged
ChrisPulman merged 2 commits intomainfrom
CP_fix-interaction-deadlock
May 4, 2026
Merged

Fix for 4280 interaction async handler scheduling#4351
ChrisPulman merged 2 commits intomainfrom
CP_fix-interaction-deadlock

Conversation

@ChrisPulman
Copy link
Copy Markdown
Member

What kind of change does this PR introduce?

Fix

What is the current behavior?

Closes #4280

What is the new behavior?

This pull request refactors the Interaction handler registration and execution logic in ReactiveUI to improve consistency, reliability, and testability, especially around asynchronous handler scenarios. It introduces a unified handler registration core, ensures asynchronous handlers yield to the current context, and updates tests to use modern async/await patterns. Several new tests are also added to verify scheduler release behavior for both task-based and observable handlers.

Core handler registration and async context improvements:

  • Introduced a private RegisterHandlerCore method to centralize handler registration and disposal logic, replacing duplicated code in RegisterHandler overloads. [1] [2]
  • Added a private YieldToCurrentContext method to ensure asynchronous handlers (both Task and IObservable-based) yield execution before invoking user code, preventing scheduler trampoline issues and improving nested interaction support. [1] [2]

Test modernization and reliability:

  • Updated all relevant tests in InteractionsTest.cs to use async/await and ToTask() instead of synchronous blocking (Wait()/FirstAsync().Wait()), improving test reliability and better reflecting real-world async usage. [1] [2] [3] [4] [5] [6]
  • Marked the InteractionsTest class with [NotInParallel] to ensure tests are not run in parallel, avoiding flakiness due to shared state.

Expanded test coverage for async handler behavior:

  • Added tests to verify that both Task-based and IObservable-based handlers release the current scheduler before executing user code, ensuring nested interactions are not blocked and behave as expected.

Test improvements for handler precedence and subscription timing:

  • Enhanced tests to more reliably detect when handlers are subscribed and to ensure correct handler precedence, especially in asynchronous scenarios, using TaskCompletionSource for precise subscription tracking. [1] [2]

These changes collectively make handler registration more robust, improve async interaction patterns, and ensure that both the implementation and test suite are future-proof and reliable.

What might this PR break?

Checklist

  • I have read the Contribute guide
  • Tests have been added or updated (for bug fixes / features)
  • Docs have been added or updated (for bug fixes / features)
  • Changes target the main branch
  • PR title follows Conventional Commits

Additional information

@ChrisPulman ChrisPulman enabled auto-merge (squash) May 4, 2026 13:14
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.86%. Comparing base (b54d29b) to head (926fec1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4351      +/-   ##
==========================================
+ Coverage   89.85%   89.86%   +0.01%     
==========================================
  Files         253      253              
  Lines        9638     9652      +14     
  Branches     1475     1476       +1     
==========================================
+ Hits         8660     8674      +14     
  Misses        734      734              
  Partials      244      244              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ChrisPulman ChrisPulman merged commit 303d184 into main May 4, 2026
10 checks passed
@ChrisPulman ChrisPulman deleted the CP_fix-interaction-deadlock branch May 4, 2026 15:00
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.

[Feature]Add Analyzer warning or Documentation regarding blocking UI calls (ShowDialog) in Interaction Handlers

2 participants