Skip to content

Serialize Linux URLSession request paths to mitigate _MultiHandle race#134

Merged
mattt merged 9 commits intomainfrom
mattt/gate-linux-urlsession
Mar 23, 2026
Merged

Serialize Linux URLSession request paths to mitigate _MultiHandle race#134
mattt merged 9 commits intomainfrom
mattt/gate-linux-urlsession

Conversation

@mattt
Copy link
Collaborator

@mattt mattt commented Feb 19, 2026

Resolves #127
Alternative to / complement of #128

Copy link

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 addresses a critical use-after-free crash on Linux caused by a thread-safety bug in swift-corelibs-foundation's URLSession._MultiHandle. The fix introduces a serialization gate (LinuxURLSessionRequestGate) that ensures only one URLSession request executes at a time on Linux, mitigating concurrent access to the problematic _MultiHandle singleton.

Changes:

  • Adds LinuxURLSessionRequestGate actor to serialize URLSession operations on Linux
  • Wraps all data(for:) and streaming calls with the gate's lock on Linux platforms
  • Maintains separate code paths for Linux and non-Linux platforms using conditional compilation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

JonasProgrammer and others added 3 commits March 23, 2026 04:51
* deps: add trait-based import of AsyncHTTPClient

* feat: implement transparent AsyncHTTPClient wrapper

* deps: conditionally include trait in EventSource

* Increase HTTP request timeout from 60 to 180 seconds

---------

Co-authored-by: Leonhard Solbach <49833472+KotlinFactory@users.noreply.github.com>
@mattt
Copy link
Collaborator Author

mattt commented Mar 23, 2026

@JonasProgrammer @KotlinFactory Thanks again for all of your help with this. I'm working to cut a new minor release with this today.

@mattt mattt merged commit 226542d into main Mar 23, 2026
3 checks passed
@mattt mattt deleted the mattt/gate-linux-urlsession branch March 23, 2026 12:08
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.

Use-after-free crash on Linux: URLSession._MultiHandle thread-safety bug

3 participants