Skip to content

[stable] [SwiftPM] Fix concurrent directory/file/symlink creation crashes - #187864

Merged
auto-submit[bot] merged 2 commits into
flutter:flutter-3.44-candidate.0from
bkonyi:cherry-pick-186953-to-stable
Jun 17, 2026
Merged

[stable] [SwiftPM] Fix concurrent directory/file/symlink creation crashes#187864
auto-submit[bot] merged 2 commits into
flutter:flutter-3.44-candidate.0from
bkonyi:cherry-pick-186953-to-stable

Conversation

@bkonyi

@bkonyibkonyi commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

This pull request is created by automatic cherry pick workflow
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.

Issue Link:

#186953

Impact Description:

During concurrent target builds using SwiftPM, multiple processes might try to create or clean up plugin symlinks at the same time, leading to crashes (e.g., due to file already existing or being deleted while being accessed).

Changelog Description:

[flutter/186953] When building concurrently with SwiftPM [on macOS/iOS], fix crashes caused by concurrent directory/file/symlink creation.

Workaround:

Avoid concurrent builds, or disable SwiftPM if possible.

Risk:

What is the risk level of this cherry-pick?

  • Low
  • Medium
  • High

Test Coverage:

Are you confident that your fix is well-tested by automated tests?

  • Yes
  • No

Validation Steps:

Run concurrent builds of a project using SwiftPM and verify that it no longer crashes during symlink creation.

…tter#186953)
Robust SwiftPM symlink creation. Addresses potential race conditions
during concurrent target builds where creating or cleaning up plugin
symlinks might crash.
- Check if symlink already exists and points to the correct target
before deleting or recreating to prevent concurrency issues.
- Clean up existing directories, files, or links properly using a switch
expression.
- Catch OS Error 17 (File exists) gracefully if another concurrent
process creates the symlink at the same instant, and verify it points to
the correct target.
- Added 4 robust unit tests covering existing files, directories, broken
symlinks, and concurrent creation failures.
TAG=agy
CONV=89884076-7f0a-4371-b5e1-6b4cae692891
@bkonyi
bkonyi requested review from a team as code ownersJune 11, 2026 15:46
@bkonyibkonyi added the cp: review Cherry-picks in the review queue label Jun 11, 2026
@flutter-dashboardflutter-dashboardBot added the CICD Run CI/CD label Jun 11, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter.

Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed.

@github-actionsgithub-actionsBot added tool Affects the "flutter" command-line tool. See also t: labels. platform-macos Building on or for macOS specifically a: desktop Running on desktop team-ios Owned by iOS platform team team-macos Owned by the macOS platform team labels Jun 11, 2026

@gemini-code-assistgemini-code-assistBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enhances ErrorHandlingFileSystem to improve the robustness of file system operations, introducing retry logic for transient Windows locks, type-agnostic disk presence checks in deleteIfExists to handle broken symlinks, and wrapping additional asynchronous and synchronous operations. It also updates SwiftPackageManager to prevent parallel build race conditions during symlink creation. Feedback on the changes highlights a compilation error due to the use of unsupported leading dot shorthand syntax for enum values in Dart, and notes that the public member overrideWindowsRetryBackoffs is missing required documentation.

Comment threadpackages/flutter_tools/lib/src/base/error_handling_io.dart
Comment threadpackages/flutter_tools/lib/src/base/error_handling_io.dart
@LongCatIsLooong

Copy link
Copy Markdown
Contributor

Linux analyze is failing with

info • Use an initializing formal to assign a parameter to a field. Try using an initialing formal ('this.delegate') to initialize the field • packages/flutter_tools/test/general.shard/macos/swift_package_manager_test.dart:846:7 • prefer_initializing_formals

But it did not complain on https://github.com/flutter/flutter/pull/186953/changes#diff-b0bd7898776cf9682ab468c8b86ad4c691d242364a058e0e5e31f64e40c6c050R846. Was this lint relaxed on master because of primary constructors?

@github-actionsgithub-actionsBot removed the CICD Run CI/CD label Jun 17, 2026
@bkonyibkonyi added the CICD Run CI/CD label Jun 17, 2026
@bkonyi

Copy link
Copy Markdown
ContributorAuthor

Linux analyze is failing with

info • Use an initializing formal to assign a parameter to a field. Try using an initialing formal ('this.delegate') to initialize the field • packages/flutter_tools/test/general.shard/macos/swift_package_manager_test.dart:846:7 • prefer_initializing_formals

But it did not complain on https://github.com/flutter/flutter/pull/186953/changes#diff-b0bd7898776cf9682ab468c8b86ad4c691d242364a058e0e5e31f64e40c6c050R846. Was this lint relaxed on master because of primary constructors?

I'm not quite sure what happened here. There was a patch on master to fix this, but it wasn't flagged when the original PR landed (81742d2).

I've made a minimal patch to this PR to fix the analysis error. I'll do the same for the beta CP PR as well.

@LongCatIsLooongLongCatIsLooong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CPLGTM.

The new commit fix analysis failure only contains minimal changes to fix the an analyzer warning and shouldn't be an issue when merged back to master.

@LongCatIsLooongLongCatIsLooong added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 17, 2026
@auto-submit
auto-submitBot merged commit 0700fc3 into flutter:flutter-3.44-candidate.0Jun 17, 2026
153 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktopRunning on desktopautosubmitMerge PR when tree becomes green via auto submit AppCICDRun CI/CDcp: reviewCherry-picks in the review queueplatform-macosBuilding on or for macOS specificallyteam-iosOwned by iOS platform teamteam-macosOwned by the macOS platform teamtoolAffects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@bkonyi@LongCatIsLooong