Skip to content

[SwiftPM] Fix concurrent directory/file/symlink creation crashes#186953

Merged
auto-submit[bot] merged 16 commits into
flutter:masterfrom
bkonyi:fix-swiftpm-symlink-crashes
Jun 3, 2026
Merged

[SwiftPM] Fix concurrent directory/file/symlink creation crashes#186953
auto-submit[bot] merged 16 commits into
flutter:masterfrom
bkonyi:fix-swiftpm-symlink-crashes

Conversation

@bkonyi

@bkonyi bkonyi commented May 22, 2026

Copy link
Copy Markdown
Contributor

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 owners May 22, 2026 16:00
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 22, 2026
@github-actions github-actions Bot 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 May 22, 2026

@gemini-code-assist gemini-code-assist Bot 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 implements more robust symlink creation for macOS Swift packages, adding checks for existing file system entities and handling race conditions in parallel builds. Review feedback identifies a critical bug where the use of continue skips necessary plugin data collection for the manifest and notes a missing import in the test file required for the new mock file system classes.

Comment thread packages/flutter_tools/lib/src/macos/swift_package_manager.dart Outdated
@github-actions github-actions Bot removed the CICD Run CI/CD label May 22, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 22, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 22, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 22, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 22, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 22, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 22, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 22, 2026
Comment thread packages/flutter_tools/lib/src/base/error_handling_io.dart Outdated
Comment thread packages/flutter_tools/lib/src/base/error_handling_io.dart Outdated
Comment thread packages/flutter_tools/lib/src/base/error_handling_io.dart
Comment thread packages/flutter_tools/lib/src/dart/language_version.dart
Comment thread packages/flutter_tools/lib/src/macos/swift_package_manager.dart Outdated
Comment thread packages/flutter_tools/lib/src/macos/swift_package_manager.dart Outdated
Comment thread packages/flutter_tools/lib/src/base/error_handling_io.dart Outdated
Comment thread packages/flutter_tools/lib/src/base/error_handling_io.dart Outdated
Comment thread packages/flutter_tools/lib/src/base/error_handling_io.dart Outdated
Comment thread packages/flutter_tools/lib/src/base/error_handling_io.dart
Comment thread packages/flutter_tools/lib/src/base/error_handling_io.dart Outdated
Comment thread packages/flutter_tools/lib/src/base/error_handling_io.dart Outdated
Comment thread packages/flutter_tools/lib/src/base/error_handling_io.dart Outdated
@github-actions github-actions Bot removed the CICD Run CI/CD label May 26, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 26, 2026
bkonyi added a commit to bkonyi/flutter that referenced this pull request May 26, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 26, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 26, 2026
bkonyi added a commit to bkonyi/flutter that referenced this pull request May 26, 2026
@bkonyi bkonyi force-pushed the fix-swiftpm-symlink-crashes branch from a3f1deb to 68ac22c Compare May 26, 2026 20:36
bkonyi added 2 commits May 28, 2026 18:15
Remove private initializing formal from `_ErrorInjectingLink` constructor to ensure compatibility with older Dart versions if needed.

This rewrites the constructor to use a standard initializer list instead.
@bkonyi bkonyi force-pushed the fix-swiftpm-symlink-crashes branch from 13102f4 to 4fdd469 Compare May 28, 2026 19:00
@github-actions github-actions Bot removed the CICD Run CI/CD label May 28, 2026
@bkonyi bkonyi added the CICD Run CI/CD label May 28, 2026
@bkonyi bkonyi requested a review from vashworth May 28, 2026 23:43

@vashworth vashworth 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.

LGTM

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 3, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jun 3, 2026
Merged via the queue into flutter:master with commit 9716071 Jun 3, 2026
166 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 3, 2026
cbracken added a commit to cbracken/flutter that referenced this pull request Jun 3, 2026
Fixes a prefer_initializing_formals lint issue introduced in flutter#186953.
Updates the constructor to use an initializing formal parameter
(this.delegate) instead of manually assigning the field.
pull Bot pushed a commit to jinzaizhichi/flutter that referenced this pull request Jun 3, 2026
Fixes a prefer_initializing_formals lint failure introduced in flutter#186953.
Updates the constructor to use an initializing formal parameter
(this.delegate) instead of manually assigning the field.

Fixes lint error:
```
Analyzing Flutter repository...                                  2,764ms
   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
1 issue found. (1 new) • analyzed 1 file (ran in 2.76s)
```

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->


## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [X] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

If this change needs to override an active code freeze, provide a
comment explaining why. The code freeze workflow can be overridden by
code reviewers. See pinned issues for any active code freezes with
guidance.

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jun 3, 2026
…11832)

Manual roll requested by tarrinneal@google.com

flutter/flutter@701665b...2ba5420

2026-06-03 engine-flutter-autoroll@skia.org Roll Packages from 818b310 to b11504f (8 revisions) (flutter/flutter#187511)
2026-06-03 mdebbar@google.com Add new file patterns for team-web labeler (flutter/flutter#187397)
2026-06-03 engine-flutter-autoroll@skia.org Roll Skia from 279b17fe9fc1 to d625048c853a (12 revisions) (flutter/flutter#187483)
2026-06-03 chris@bracken.jp [SwiftPM] Fix prefer_initializing_formals lint (flutter/flutter#187502)
2026-06-03 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from q27k7_um1GvVrySZS... to ap7MhLX4TdpWRrLS_... (flutter/flutter#187478)
2026-06-03 bkonyi@google.com [SwiftPM] Fix concurrent directory/file/symlink creation crashes (flutter/flutter#186953)
2026-06-03 flar@google.com [Impeller] Fix positioning of text shadow masks (flutter/flutter#187460)
2026-06-02 burak.karahan@mail.ru Remove Material imports from painting tests (flutter/flutter#186937)
2026-06-02 awolff@google.com Add android_hardware_smoke_test integration tests (flutter/flutter#187130)
2026-06-02 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#187471)
2026-06-02 pq@users.noreply.github.com [flutter tool] propagate analytics env to sub-tools (flutter/flutter#186780)
2026-06-02 30870216+gaaclarke@users.noreply.github.com Adds macro for fragment shaders to support flutter <= 3.44 (flutter/flutter#187316)
2026-06-02 116356835+AbdeMohlbi@users.noreply.github.com Small clean-up in different java files under `engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/` (flutter/flutter#186631)
2026-06-02 1961493+harryterkelsen@users.noreply.github.com refactor(web): Unify ui.Path code for CanvasKit and Skwasm (flutter/flutter#187331)
2026-06-02 engine-flutter-autoroll@skia.org Roll Packages from f5d50ca to 818b310 (2 revisions) (flutter/flutter#187441)
2026-06-02 faheemabbas766@gmail.com Allow selecting multi-digit device options (flutter/flutter#186184)
2026-06-02 puneetkukreja98@gmail.com Improve error message for type mismatch in Navigator.pop and maybePop. (flutter/flutter#186571)
2026-06-02 sanaullah.383@hotmail.com Remove semantics_tester import from material_button_test.dart (flutter/flutter#184807)
2026-06-02 bkonyi@google.com [flutter_tools] Refactor hostPlatform to use Abi.current() (flutter/flutter#185369)
2026-06-02 mvincentong@gmail.com Clean up avoid_type_to_string suppressions (flutter/flutter#186869)
2026-06-02 202459002+Lukes-Lair@users.noreply.github.com Update Flutter documentation links in flutter_console.bat (flutter/flutter#187354)
2026-06-02 154381524+flutteractionsbot@users.noreply.github.com Revert "[Impeller] Allow attaching specific texture mip levels and slices" (flutter/flutter#187445)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC stuartmorgan@google.com,tarrinneal@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…lutter#11832)

Manual roll requested by tarrinneal@google.com

flutter/flutter@701665b...2ba5420

2026-06-03 engine-flutter-autoroll@skia.org Roll Packages from 818b310 to b11504f (8 revisions) (flutter/flutter#187511)
2026-06-03 mdebbar@google.com Add new file patterns for team-web labeler (flutter/flutter#187397)
2026-06-03 engine-flutter-autoroll@skia.org Roll Skia from 279b17fe9fc1 to d625048c853a (12 revisions) (flutter/flutter#187483)
2026-06-03 chris@bracken.jp [SwiftPM] Fix prefer_initializing_formals lint (flutter/flutter#187502)
2026-06-03 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from q27k7_um1GvVrySZS... to ap7MhLX4TdpWRrLS_... (flutter/flutter#187478)
2026-06-03 bkonyi@google.com [SwiftPM] Fix concurrent directory/file/symlink creation crashes (flutter/flutter#186953)
2026-06-03 flar@google.com [Impeller] Fix positioning of text shadow masks (flutter/flutter#187460)
2026-06-02 burak.karahan@mail.ru Remove Material imports from painting tests (flutter/flutter#186937)
2026-06-02 awolff@google.com Add android_hardware_smoke_test integration tests (flutter/flutter#187130)
2026-06-02 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#187471)
2026-06-02 pq@users.noreply.github.com [flutter tool] propagate analytics env to sub-tools (flutter/flutter#186780)
2026-06-02 30870216+gaaclarke@users.noreply.github.com Adds macro for fragment shaders to support flutter <= 3.44 (flutter/flutter#187316)
2026-06-02 116356835+AbdeMohlbi@users.noreply.github.com Small clean-up in different java files under `engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/` (flutter/flutter#186631)
2026-06-02 1961493+harryterkelsen@users.noreply.github.com refactor(web): Unify ui.Path code for CanvasKit and Skwasm (flutter/flutter#187331)
2026-06-02 engine-flutter-autoroll@skia.org Roll Packages from f5d50ca to 818b310 (2 revisions) (flutter/flutter#187441)
2026-06-02 faheemabbas766@gmail.com Allow selecting multi-digit device options (flutter/flutter#186184)
2026-06-02 puneetkukreja98@gmail.com Improve error message for type mismatch in Navigator.pop and maybePop. (flutter/flutter#186571)
2026-06-02 sanaullah.383@hotmail.com Remove semantics_tester import from material_button_test.dart (flutter/flutter#184807)
2026-06-02 bkonyi@google.com [flutter_tools] Refactor hostPlatform to use Abi.current() (flutter/flutter#185369)
2026-06-02 mvincentong@gmail.com Clean up avoid_type_to_string suppressions (flutter/flutter#186869)
2026-06-02 202459002+Lukes-Lair@users.noreply.github.com Update Flutter documentation links in flutter_console.bat (flutter/flutter#187354)
2026-06-02 154381524+flutteractionsbot@users.noreply.github.com Revert "[Impeller] Allow attaching specific texture mip levels and slices" (flutter/flutter#187445)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC stuartmorgan@google.com,tarrinneal@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@bkonyi bkonyi added the cp:beta label Jun 11, 2026
auto-submit Bot pushed a commit that referenced this pull request Jun 17, 2026
…shes (#187864)

This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request)
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?

### Test Coverage:
Are you confident that your fix is well-tested by automated tests?

### Validation Steps:
Run concurrent builds of a project using SwiftPM and verify that it no longer crashes during symlink creation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop CICD Run CI/CD cp:beta cp:stable platform-macos Building on or for macOS specifically team-ios Owned by iOS platform team team-macos Owned by the macOS platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants