Skip to content

[Tool] Concurrency & Race Conditions in SwiftPM Integration #188446

Closed

Description

@bkonyi

This issue is one of the top crashers identified in the Flutter 3.44.3 stable release.


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.

Root Cause

In swift_package_manager.dart, generatePluginsSwiftPackage deletes and recreates project.relativeSwiftPackagesDirectory (ephemeral/Packages). Parallel Xcode targets (e.g., main app and extensions) invoke the Flutter tool concurrently, leading to destructive races where one process deletes the directory while another is writing to it.

Proposed Solution

  1. Introduce process-safe file locking (.swift_pm.lock) with retries to serialize directory preparation.
  2. Implement non-destructive, incremental cleanup of the directory (only deleting stale symlinks/files instead of the entire directory).
  3. Implement content-aware write skipping for Package.swift and placeholder source files to avoid redundant writes and prevent unnecessary Xcode project re-indexing.

Activity

  1. self-assigned this
    on Jun 23, 2026
  2. added
    P2
    team-tool
    triaged-tool
    on Jun 23, 2026
  3. changed the title [-]Concurrency & Race Conditions in SwiftPM Integration[/-] [+][Tool] Concurrency & Race Conditions in SwiftPM Integration[/+] on Jun 23, 2026
  4. github-actions commented on Aug 21, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  5. locked as resolved and limited conversation to collaborators on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2team-tooltriaged-tool

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions