Open
Description
Consider the following code:
extension TrackedFileDescriptor {
internal consuming func createPlatformDiskIO() -> TrackedPlatformDiskIO {
let dispatchIO: DispatchIO = DispatchIO(
type: .stream,
fileDescriptor: self.platformDescriptor(),
queue: .global(),
cleanupHandler: { error in
// Close the file descriptor
if self.closeWhenDone {
try? self.safelyClose()
}
}
)
return .init(dispatchIO, closeWhenDone: self.closeWhenDone)
}
}
cleanupHandler
is mis-annotated. It should be @Sendable
but is not. This means the compiler allows the closure to capture a reference to and mutate self in concurrently-executing code, which it should not. It's unclear whether this is behaving as expected.