Skip to content

Sendable conformance on _AsyncBytesBuffer.Storage allows unsafe concurrent access #120

Closed
@mhjacobson

Description

@mhjacobson

In AsyncBufferedByteIterator.swift, _AsyncBytesBuffer.Storage (a class) conforms to Sendable, allowing it to be passed across concurrency boundaries. Since concurrent access is allowed, classes conforming to Sendable are responsible for implementing internal synchronization, but Storage doesn't have any.

This means that it's possible to construct data races on the buffer of an _AsyncBytesBuffer.Storage (through copies of an AsyncBufferedByteIterator). (See this gist for an example.) Here's what happens:

  1. Multiple instances of _AsyncBytesBuffer value can share a single Storage. If the multiple instances are read from on separate threads, then their readFunctions may be called concurrently, with the same pointer argument. Since the job of the readFunction is to fill in the pointee bytes, there is a write/write data race on those bytes

  2. Similarly, one copy may be reading from the Storage while another is calling its readFunction, producing a read/write data race on the bytes

Metadata

Metadata

Assignees

Labels

v1.0Work leading up first API stable version

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions