Skip to content

Multi-thread pulling of out put from AsyncProcess #8549

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

Closed
wants to merge 11 commits into from

Conversation

dschaefer2
Copy link
Member

We are seeing hangs on Windows when SwiftPM tests itself. Looking at how AsyncProcess pulls stdout and stderr, I can see that there may be conditions where the streams aren't fully drained causing the hang. The proper way to do this, like it's done on the other platforms is to create a thread for each stream.

We are seeing hangs on Windows when SwiftPM tests itself.
Looking at how AsyncProcess pulls stdout and stderr, I can see
that there may be conditions where the streams aren't fully drained
causing the hang. The proper way to do this, like it's done on
the other platforms is to create a thread for each stream.
A fatal error was happening in the PackageLoadingTests.
Removed the caching of the manifest loader so that if it fails
it can properly throw an exception.
@dschaefer2
Copy link
Member Author

@swift-ci please test

Copy link
Contributor

@jakepetroules jakepetroules left a comment

Choose a reason for hiding this comment

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

Heh, I've lost count of how many times I've fixed this same problem with uses of Process. Really looking forward to adopting swift-subprocess everywhere, which is async-native.

Looks like readabilityHandler is invoked on a private serial Dispatch queue owned by the FileHandle; I'm not sure this is a scenario where a hang could be caused, but it's hard to tell since the Swift Concurrency / GCD interaction is complex. This approach is worth trying though, since a pthread provides a pretty strong independence guarantee.

@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

@@ -17,7 +17,6 @@ import _InternalTestSupport
import XCTest

class PackageDescriptionLoadingTests: XCTestCase, ManifestLoaderDelegate {
lazy var manifestLoader = ManifestLoader(toolchain: try! UserToolchain.default, delegate: self)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: can we instantiate manifestLoader in a setUp(...) call to ensure each test instantiates/creates its own object?

@@ -17,7 +17,6 @@ import _InternalTestSupport
import XCTest

class PackageDescriptionLoadingTests: XCTestCase, ManifestLoaderDelegate {
lazy var manifestLoader = ManifestLoader(toolchain: try! UserToolchain.default, delegate: self)
var parsedManifest = ThreadSafeBox<AbsolutePath>()
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: can we instantiate parsedManifest in a setUp(...) call to ensure each test instantiates/creates its own object?

@dschaefer2
Copy link
Member Author

Still hanging, even removing the --parallel. Trying one more attempt at going pure win32.

But, yes, subprocess would come in handy right now.

To make sure it's clear what AsyncProcess is doing on Windows,
Replace the use of Foundation's Process with direct calls
to win32's CreateProcessW.
@dschaefer2
Copy link
Member Author

Consistently seeing the GitRepository tests hanging. Will try a couple of more times to confirm.

@dschaefer2
Copy link
Member Author

@swift-ci please test self hosted windows

@dschaefer2
Copy link
Member Author

Huh, that was it. I'm going to abandon this and go back to using Foundation.Process but with the multi-threaded reads. And then make sure multiple gits aren't running at the same time.

@dschaefer2 dschaefer2 closed this Apr 27, 2025
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.

4 participants