emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.6k stars 419 forks source link

Data racing issue in CocoaMQTT5 #541

Closed dahuayuan closed 1 year ago

dahuayuan commented 1 year ago
Screenshot 2023-08-08 at 09 12 22

The framework crashes from time to time as the picture shows above.

The reason is because subscriptionsWaitingAck is not thread safe. If there are many subscriptions happen simultaneously, the data racing issue will pop up. Please consider to make these variables thread safe. thanks


    /// The subscribed topics in current communication
    public var subscriptions: [String: CocoaMQTTQoS] = [:]

    fileprivate var subscriptionsWaitingAck: [UInt16: [MqttSubscription]] = [:]
    fileprivate var unsubscriptionsWaitingAck: [UInt16: [MqttSubscription]] = [:]
dahuayuan commented 1 year ago

If you enable "Thread sanitizer", you are able to see the data racing issue easily:

Screenshot 2023-08-08 at 09 35 06 Screenshot 2023-08-08 at 09 32 59
jeffery812 commented 1 year ago

It is fixed in PR