Sitelet https://github.com/flutter/flutter/pull/191091
Skip to content

[stable] [Tool] Fix SwiftPM race condition during parallel Xcode builds - #191091

Closed
bkonyi wants to merge 1 commit into
flutter:flutter-3.47-candidate.0from
bkonyi:cherry-pick-188451-to-stable
Closed

bkonyi wants to merge 1 commit into
flutter:flutter-3.47-candidate.0from
bkonyi:cherry-pick-188451-to-stable

Conversation

@bkonyi

@bkonyi bkonyi commented Aug 13, 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:

What is the link to the issue this cherry-pick is addressing?

#188446

Impact Description:

What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)?
Does it impact development (ex. flutter doctor crashes when Android Studio is installed),
or the shipping of production apps (the app crashes on launch).
This information is for domain experts and release engineers to understand the consequences of saying yes or no to the cherry pick.

The Flutter tool experiences a race condition when preparing the Swift Packages directory during parallel Xcode builds, leading to FileSystemException (OS Error: Directory not empty, errno = 66) or PathExistsException. This is one of the top crashers identified in the Flutter 3.44.3 stable release. It impacts development when building multi-target iOS/macOS applications in parallel.

Changelog Description:

Explain this cherry pick:

  • In one line that is accessible to most Flutter developers.
  • That describes the state prior to the fix.
  • That includes which platforms are impacted.
    See best practices for examples.

[flutter/188446] When building multi-target applications in parallel on iOS and macOS, a race condition in SwiftPM integration causes FileSystemException.

Workaround:

Is there a workaround for this issue?

Run Xcode builds sequentially (disable parallel target builds) or build targets one by one.

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:

What are the steps to validate that this fix works?

  1. Enable Swift PM in a Flutter project.
  2. Add multiple targets (e.g. App and Share Extension) that use Swift PM plugins.
  3. Build the project in Xcode with parallel builds enabled.
  4. Verify the build succeeds without FileSystemException or PathExistsException in ephemeral/Packages.

…er#188451)

Xcode builds multi-target applications in parallel, invoking the Flutter
build pipeline concurrently. This leads to a destructive race condition
in `generatePluginsSwiftPackage` where one process deletes the ephemeral
packages directory while another is writing to it, causing
`FileSystemException` or `PathExistsException`.

This change implements:

1. Process-safe file locking (`.swift_pm.lock`) with retry loops to
serialize directory preparation across parallel builds.

2. Non-destructive, incremental cleanup of obsolete symlinks rather than
deleting the entire directory.

3. Content-aware write skipping for `Package.swift` and placeholder
source files to avoid redundant writes and prevent unnecessary Xcode
project re-indexing.

Fixes flutter#188446
@bkonyi bkonyi added the cp: review Cherry-picks in the review queue label Aug 13, 2026
@bkonyi
bkonyi requested review from a team as code owners August 13, 2026 23:59
@bkonyi bkonyi added the cp: review Cherry-picks in the review queue label Aug 13, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 13, 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-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 Aug 13, 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 introduces file-locking synchronization for Swift Package Manager operations to handle concurrent builds, cleans up stale plugin symlinks, and optimizes Package.swift and placeholder source generation by avoiding redundant writes. Feedback suggests adding a timeout to the retry loop in runLocked to prevent infinite hangs on persistent FileSystemExceptions.

Comment thread packages/flutter_tools/lib/src/base/file_system.dart
@bkonyi bkonyi closed this Aug 14, 2026
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: review Cherry-picks in the review queue 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.

1 participant