Skip to content

[mTLS] Use session-level auth handling and avoid main queue#4591

Merged
bgoncal merged 2 commits into
mainfrom
fix-mtls-urlsession
Apr 30, 2026
Merged

[mTLS] Use session-level auth handling and avoid main queue#4591
bgoncal merged 2 commits into
mainfrom
fix-mtls-urlsession

Conversation

@bgoncal
Copy link
Copy Markdown
Member

@bgoncal bgoncal commented Apr 30, 2026

Summary

Screenshots

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#

Any other notes

@bgoncal bgoncal self-assigned this Apr 30, 2026
Copilot AI review requested due to automatic review settings April 30, 2026 11:26
@bgoncal bgoncal added the mtls label Apr 30, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts onboarding connectivity checks to handle mTLS/server-trust challenges at the session delegate level and removes the URLSession delegate’s main-queue pinning to avoid TLS handshake stalls during UI transitions.

Changes:

  • Create the URLSession with delegateQueue: nil instead of .main.
  • Refactor auth-challenge handling into a shared helper and add a session-level urlSession(_:didReceive:completionHandler:) handler.
  • Dispatch alert presentation to the main queue.

Comment thread Sources/App/Onboarding/API/Steps/OnboardingAuthStepConnectivity.swift Outdated
Comment thread Sources/App/Onboarding/API/Steps/OnboardingAuthStepConnectivity.swift Outdated
Comment thread Sources/App/Onboarding/API/Steps/OnboardingAuthStepConnectivity.swift Outdated
- Revert delegateQueue back to `.main`. Reverts the speculative queue
  switch that introduced data-race risk on the per-task dictionaries
  and pushed UIKit alert configuration onto the URLSession's background
  delegate queue.
- Drop the per-task `[Int: ...]` dictionaries in favour of a single
  in-flight resolver and three plain `Bool` flags, reset at the top of
  every `performConnection`. Eliminates the latent stale-entry bug when
  the same step instance handles multiple `perform(point:)` calls.
- The session-level challenge handler now reads `currentResolver`
  directly, so it can no longer pick a leftover entry from a previous
  run.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@75aab68). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4591   +/-   ##
=======================================
  Coverage        ?   43.24%           
=======================================
  Files           ?      275           
  Lines           ?    16700           
  Branches        ?        0           
=======================================
  Hits            ?     7222           
  Misses          ?     9478           
  Partials        ?        0           

☔ 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.

@bgoncal bgoncal merged commit fb2e82d into main Apr 30, 2026
14 of 15 checks passed
@bgoncal bgoncal deleted the fix-mtls-urlsession branch April 30, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants