Skip to content

Commit 5af2b3a

Browse files
authored
[Collections] Potential fix for race in list collections (#3318)
Motivation: `testHappyRefresh` crashed in https://ci.swift.org/job/oss-swift-package-centos-8/975 ``` Test Suite 'PackageCollectionsTests' started at 2021-03-02 22:01:52.483 Test Case 'PackageCollectionsTests.testHappyRefresh' started at 2021-03-02 22:01:52.483 Exited with signal code 11 ``` This is similar to #3232 Modifications: Both `testHappyRefresh` and `testBrokenRefresh` call `listCollections` after `refreshCollections`, and part of the `listCollections` code where we read collection blobs from the database might be racy since we are not using `ThreadSafeArrayStore`.
1 parent e953519 commit 5af2b3a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sources/PackageCollections/Storage/SQLitePackageCollectionsStorage.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ final class SQLitePackageCollectionsStorage: PackageCollectionsStorage, Closable
341341
// go to db if not found
342342
self.queue.async {
343343
do {
344-
var blobs = [Data]()
344+
let blobs = ThreadSafeArrayStore<Data>()
345345
if let identifiers = identifiers {
346346
var index = 0
347347
while index < identifiers.count {
@@ -374,7 +374,7 @@ final class SQLitePackageCollectionsStorage: PackageCollectionsStorage, Closable
374374
})
375375
} else {
376376
collections = .init()
377-
blobs.forEach { data in
377+
blobs.get().forEach { data in
378378
self.queue.async(group: sync) {
379379
if let collection = try? self.decoder.decode(Model.Collection.self, from: data) {
380380
collections.append(collection)

0 commit comments

Comments
 (0)