Skip to content

Problematic usage of DispatchIO due to mis-annotated Sendable #106

Open
@jakepetroules

Description

@jakepetroules

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions