Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-12272] FileManager temporary directory creation not thread-safe on Linux #4397

Closed
swift-ci opened this issue Feb 26, 2020 · 1 comment
Closed

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-12272
Radar None
Original Reporter fumoboy007 (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 5.1.4 (swift-5.1.4-RELEASE)
Target: x86_64-unknown-linux-gnu

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee fumoboy007 (JIRA)
Priority Medium

md5: 613ef235136c394ef196b7507cd44193

relates to:

  • SR-9606 Possible race condition in FileManager.createDirectory(atPath:withIntermediateDirectories:attributes:error:)
  • SR-12737 FileManager.createDirectory can throw fileWriteFileExists even when withIntermediateDirectories is true
  • SR-12569 createDirectory(at: ..., withIntermediateDirectories:true) fails spuriously with EEXIST if it races

Issue Description:

Sample code:

import Dispatch
import Foundation

let dispatchGroup = DispatchGroup()
for _ in 0..<10 {
   DispatchQueue.global().async(group: dispatchGroup) {
      _ = try! FileManager.default.url(for: .itemReplacementDirectory,
                                       in: .userDomainMask,
                                       appropriateFor: URL(fileURLWithPath: NSTemporaryDirectory(),
                                                           isDirectory: true),
                                       create: true)
   }
}

dispatchGroup.wait()

Crash:

Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=516 "A file with the same name already exists."
@swift-ci
Copy link
Contributor Author

Comment by Darren Mo (JIRA)

See pull request.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant