-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Use readData
to read data from a pipe instead of availableData
#8047
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
Conversation
@swift-ci Please test |
Using `availableData` causes parallel XCTest execution to hang on Windows if the tests output significant data to stderr.
@swift-ci Please test |
@swift-ci Please test Windows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we all have scars from using availableData to read stdout/stderr. Thanks @ahoppen!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this will work?. availableData just calls the same underlying API as read(upToCount:), and it still has the ability to block the calling thread.
private func _checkFileHandle() {
precondition(self._handle != INVALID_HANDLE_VALUE, "Invalid file handle")
}
open var availableData: Data {
_checkFileHandle()
do {
let readResult = try _readDataOfLength(Int.max, untilEOF: false)
return readResult.toData()
} catch {
fatalError("\(error)")
}
}
public func read(upToCount count: Int) throws -> Data? {
guard self != FileHandle._nulldeviceFileHandle else { return nil }
let result = try _readDataOfLength(count, untilEOF: true)
return result.length == 0 ? nil : result.toData()
}
Yes, I tested that we no longer see the hang when using |
That feels true. The hangs I've seen have been at the end of the stream where EOF isn't properly detected. |
Using
availableData
causes parallel XCTest execution to hang on Windows if the tests output significant data to stderr.