Skip to content

Change PackageCollectionSigning API from callback-based to async/await #6609

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

Merged
merged 4 commits into from
May 25, 2023

Conversation

yim-lee
Copy link
Contributor

@yim-lee yim-lee commented May 24, 2023

Motivation:
Package collection signing crashes with code 139 on Linux (Ubuntu Jammy). Adding a signed collection also fails.

Modifications:

  • Change PackageCollectionSigning API from callback-based to async/await
  • Certificate validation is async/await instead of callback-based
  • Change PackageCollectionSigning to actor since accessing self.observabilityScope also causes crash

Motivation:
Package collection signing crashes with code 139 on Linux (Ubuntu Jammy). Adding a signed collection also fails.

Modifications:
- Change `PackageCollectionSigning` API from callback-based to async/await
- Certificate validation is async/await instead of callback-based
- Change `PackageCollectionSigning` to actor since accessing `self.observabilityScope` also causes crash
@yim-lee
Copy link
Contributor Author

yim-lee commented May 24, 2023

@swift-ci please smoke test

@yim-lee
Copy link
Contributor Author

yim-lee commented May 24, 2023

Tested swift package-collection add locally on macOS and Ubuntu Jammy (docker image).

} else if !Self.isSignatureCheckSupported {
callback(.failure(StringError("Unsupported platform")))
} else {
// Check the signature
let signatureResults = ThreadSafeArrayStore<Result<Void, Error>>()
certPolicyKeys.forEach { certPolicyKey in
self.signatureValidator.validate(signedCollection: signedCollection, certPolicyKey: certPolicyKey) { result in
let count = signatureResults.append(result)
Task {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀 the key change in this file. The rest is mostly formatting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the change to run this in a task context, or something more?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To run async code in a Task yes. It is inside a loop and each task updates the signatureResults array.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we use a task group maybe to help collect the results and make waiting for all the tasks to complete easier? just an idea, not sure if helpful

Copy link
Contributor

@MaxDesiatov MaxDesiatov May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for a task group or async let if either can be used here, otherwise we end up not utilizing structured concurrency benefits

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amended 073d7df

@yim-lee
Copy link
Contributor Author

yim-lee commented May 24, 2023

@swift-ci please smoke test

@yim-lee
Copy link
Contributor Author

yim-lee commented May 24, 2023

@swift-ci please test Windows platform

guard SignatureError.invalidSignature == error as? SignatureError else {
return XCTFail("Expected SignatureError.invalidSignature")
}
private func readTestCertData(path: (AbsolutePath) -> AbsolutePath, callback: (Result<Data, Error>) -> Void) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be made async? The tests calling it seem to be async already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amended 813bd98

@yim-lee
Copy link
Contributor Author

yim-lee commented May 24, 2023

@swift-ci please smoke test

@yim-lee
Copy link
Contributor Author

yim-lee commented May 24, 2023

@swift-ci please test Windows platform

@yim-lee yim-lee merged commit a4a5aa7 into swiftlang:main May 25, 2023
@yim-lee yim-lee deleted the async-collection-signer branch May 25, 2023 18:50
yim-lee added a commit to yim-lee/swift-package-collection-generator that referenced this pull request May 25, 2023
yim-lee added a commit to swiftlang/swift-package-collection-generator that referenced this pull request May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants