Skip to content

Commit ef8b64d

Browse files
fix: Concurrent error collection blocks correctly
Previously, errors would occasionally be underreported, which caused randomly failing tests. This is because when `append(error:` was called concurrently, it occasionally would overwrite a concurrently written `_errorsQueue`
1 parent 6e483ae commit ef8b64d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Sources/GraphQL/Execution/Execute.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ public final class ExecutionContext: @unchecked Sendable {
7878
}
7979

8080
public func append(error: GraphQLError) {
81-
errors.append(error)
81+
// `append` must explicitly use the DispatchQueue and the underlying storage because by
82+
// default `append` uses separate unblocked get, modify, and replace steps.
83+
errorsQueue.sync(flags: .barrier) {
84+
self._errors.append(error)
85+
}
8286
}
8387
}
8488

@@ -849,7 +853,7 @@ func completeListValue(
849853

850854
return try await withThrowingTaskGroup(of: (Int, (any Sendable)?).self) { group in
851855
// To preserve order, match size to result, and filter out nils at the end.
852-
var results: [(any Sendable)?] = result.map { _ in nil }
856+
var results = [(any Sendable)?](repeating: nil, count: result.count)
853857
for (index, item) in result.enumerated() {
854858
group.addTask {
855859
// No need to modify the info object containing the path,

0 commit comments

Comments
 (0)