Skip to content

use serial queue to order repository lookups #7076

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Sources/SourceControl/RepositoryManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class RepositoryManager: Cancellable {
private let concurrencySemaphore: DispatchSemaphore
/// OperationQueue to park pending lookups
private let lookupQueue: OperationQueue
/// Serial queue to manage order of lookup callbacks
private let lookupCallbackSerialQueue = DispatchQueue(label: "org.swift.swiftpm.repository-manager.serial-callback")

/// The filesystem to operate on.
private let fileSystem: FileSystem
Expand Down Expand Up @@ -87,7 +89,7 @@ public class RepositoryManager: Cancellable {
// this queue and semaphore is used to limit the amount of concurrent git operations taking place
let maxConcurrentOperations = max(1, maxConcurrentOperations ?? 3*Concurrency.maxOperations/4)
self.lookupQueue = OperationQueue()
self.lookupQueue.name = "org.swift.swiftpm.repository-manager"
self.lookupQueue.name = "org.swift.swiftpm.repository-manager.concurrent"
self.lookupQueue.maxConcurrentOperationCount = maxConcurrentOperations
self.concurrencySemaphore = DispatchSemaphore(value: maxConcurrentOperations)
}
Expand Down Expand Up @@ -148,7 +150,8 @@ public class RepositoryManager: Cancellable {
if let pendingLookup = self.pendingLookups[repository] {
self.pendingLookupsLock.unlock()
// chain onto the pending lookup
return pendingLookup.notify(queue: .sharedConcurrent) {
// note the notification is done on a serial queue as the internal lookup assumes no concurrent access
return pendingLookup.notify(queue: self.lookupCallbackSerialQueue) {
// at this point the previous lookup should be complete and we can re-lookup
completion(.init(catching: {
try self.lookup(
Expand Down
3 changes: 1 addition & 2 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,9 @@ final class BuildPlanTests: XCTestCase {
}

func testPackageNameFlag() throws {
try XCTSkipIfCI() // test is disabled because it isn't stable, see rdar://118239206
let isFlagSupportedInDriver = try DriverSupport.checkToolchainDriverFlags(flags: ["package-name"], toolchain: UserToolchain.default, fileSystem: localFileSystem)
try fixture(name: "Miscellaneous/PackageNameFlag") { fixturePath in
let (stdout, _) = try executeSwiftBuild(fixturePath.appending("appPkg"), extraArgs: ["-vv"])
let (stdout, _) = try executeSwiftBuild(fixturePath.appending("appPkg"), extraArgs: ["--vv"])
XCTAssertMatch(stdout, .contains("-module-name Foo"))
XCTAssertMatch(stdout, .contains("-module-name Zoo"))
XCTAssertMatch(stdout, .contains("-module-name Bar"))
Expand Down