Skip to content
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

[SR-10690] Access race on _swiftEmptyArrayStorage #53087

Closed
jeremyabannister opened this issue May 15, 2019 · 5 comments
Closed

[SR-10690] Access race on _swiftEmptyArrayStorage #53087

jeremyabannister opened this issue May 15, 2019 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@jeremyabannister
Copy link

Previous ID SR-10690
Radar rdar://problem/45738939
Original Reporter @jeremyabannister
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: b3b0db238b3cad96a8c059c9ddd12cab

Issue Description:

The app I'm working on has suddenly started crashing seemingly due to an access race on `_swiftEmptyArrayStorage`. I have never heard of this variable before, but it is mentioned in the crash log:

Location is global '_swiftEmptyArrayStorage' at 0x7fff913c36e0 (libswiftCore.dylib+0x0000337e46f0)

Two utterly unrelated pieces of the code seem to be simultaneously accessing this global variable. One of them does approximately this:

public final class AccessRacer {
    internal var dict: [Int: [String]] = [:]

    public func thisParticipatesInAccessRace (id: Int, string: String) {
        self.dict[id] ?+= [string]
    }
}

infix operator ?+=
public func ?+= <Element> (lhs: inout [Element]?, rhs: [Element]) {
    lhs = lhs ?? []
    lhs? += rhs
}

The top item in that stack trace is `specialized Array.append<A>(contentsOf:)`. This stack trace is the one that is indicated to be doing the reading of the conflicted data. The other stack trace (which is doing the writing to the data) culminates in a function call into a third party library - the top two items in that stack trace are `flip(array:)` and finally `specialized _copySequenceToContiguousArray<A>(_:)`. Based on the information I have this seems like a Swift bug and not a me-bug. If I'm wrong, I'm sorry to waste your time. Thanks very much.

@belkadan
Copy link
Contributor

@lorentey, @kubamracek, I thought we fixed this?

@belkadan
Copy link
Contributor

Jeremy, what version of Swift are you using?

@jeremyabannister
Copy link
Author

@belkadan Swift 5.0

@lorentey
Copy link
Member

@Catfish-Man fixed this in #24078

`_swiftEmptyArrayStorage` is the singleton storage object for all empty arrays. The issue was that under some circumstances, Array.append(contentsOf🙂 made a (no-op) store into the singleton, and this tripped race detection.

@jeremyabannister
Copy link
Author

Could this still be triggered by third party libraries depending on their swift version?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants