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

Crash when build by Xcode 14.0 beta 5 (14A5294e) and run on iOS 16.0 (20A5339d) #475

Closed taolunyifan closed 1 year ago

taolunyifan commented 2 years ago

image

image

markusgrape commented 2 years ago

We have a very similar problem with our project.

leeway1208 commented 2 years ago

Hi, bro @markusgrape . Do you have a way to reproduce this issue?

jojo0899 commented 2 years ago

@leeway1208 In my project it happens during establishing connection with a MQTT broker.

markusgrape commented 2 years ago

@leeway1208 the crash seems to come directly after we connect to MQTT broker when using xcode 14.0 beta 5. The stacktrace looks very similar to the image above.

CocoaMQTT(info): Connected to x.x.x.x : 8083 CocoaMQTT(info): Enable backgrounding socket successfully (lldb) <- Crash

leeway1208 commented 2 years ago

@markusgrape Will the demo report crash either? I can't reproduce it yet, hope you can help me. Thanks~~

tonydavidcray commented 2 years ago

Same crash here. Running iPad OS beta 5 and Xcode beta 3.

iPadOS beta 3 is fine though.

markusgrape commented 2 years ago

@leeway1208 are you using Xcode beta 5/iOS 16 device? it is 100% reproducible for me when using that, every time it connects to MQTT broker there is this crash.

jojo0899 commented 2 years ago

Needs to be an issue with iOS 16. Using Xcode beta 5 with iPadOS 15 works fine.

markusgrape commented 2 years ago

@jojo0899 Not sure about this, we tested building with xcode 13 and iOS16 device without issues.

leeway1208 commented 2 years ago

I find simulator can not reproduce so far. It seems to be caused by the real IOS devices.

StevenVerheyen commented 2 years ago

We have the same issue. It works fine on iOS 16 simulators, but not on a real iOS device. Using Xcode 14 beta 5 and iOS 16.0 public beta (20A5349b).

When using Xcode 14 beta 5 with iOS 15 on a real device, it works fine though.

ridvankotan commented 2 years ago

I'm experiencing the exact same crash, and I tested with different configurations using the example project in this repo. It only happens with Xcode 14 beta 5 and iOS 16.0 public beta (20A5349b) on a real device. I haven't seen the crash for the following configurations.

leeway1208 commented 2 years ago

@ridvankotan thanks for your support

markusgrape commented 2 years ago

@leeway1208 any update on this?

leeway1208 commented 2 years ago

Hi. We are working on it. Will get back to you soon.

tonydavidcray commented 2 years ago

I wonder has the the recently released beta 7 had any impact on this ? And now beta 8?

ridvankotan commented 2 years ago

I tested with the latest iOS 16 beta 7 and Xcode beta, and we still have the same crash.

karolis1993 commented 2 years ago

Any update on this? Thanks in advance.

markusgrape commented 2 years ago

I just tested this patch https://github.com/robbiehanson/CocoaAsyncSocket/pull/802/files manually on CocoaAsyncSocket and it solved this crash for me, hopefully there is an official release soon.

kubbing commented 2 years ago

I can confirm that the above mentioned patch works.

niralishaha25 commented 2 years ago

waiting for the fix, the crash is reproducible on Xcode 14, stable release for CocoaMQTT 2.0.5

jupe1 commented 2 years ago

I also confirm that mentioned patch of CocoaAsyncSocket solves the issue. As the CocoaAsyncSocket project seems to be dead, are there any plans on dropping this dependency? As now CocoaMQTT is basically unusable on iOS 16 solely due to this issue.

riccardoch commented 2 years ago

Same issue:

The crash happens here (line 3052 GCDAsyncSocket didConnect):

[theDelegate socket:self didConnectToHost:host port:port];

riccardoch commented 2 years ago

I just tested this patch https://github.com/robbiehanson/CocoaAsyncSocket/pull/802/files manually on CocoaAsyncSocket and it solved this crash for me, hopefully there is an official release soon.

I can confirm the crash is solved changing kCFStreamNetworkServiceType from kCFStreamNetworkServiceTypeVoIP to kCFStreamNetworkServiceTypeBackground

seasonZhu commented 2 years ago

Crash happen because CocoaAsyncSocket 7.6.5 still use kCFStreamNetworkServiceTypeVoIP. To See This CocoaAsyncSocket doesn't update, you can fix it by change code yourself.

Add #import to GCDAsyncSocket.m

import <PushKit/PushKit.h>

Replace in enableBackgroundingOnSocketWithCaveat r1 = CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, PKPushTypeVoIP); r2 = CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, PKPushTypeVoIP);

Also, you disable backgroundOnSocket to false, but it's not well.

samson7s commented 2 years ago

@seasonZhu Run OK, thank you, the backgroundOnSocket is normal

samson7s commented 2 years ago

@seasonZhu Run OK, thank you, the backgroundOnSocket is normal

tomerpetel commented 2 years ago

Same here...

StevenVerheyen commented 2 years ago

Any update on when there will be an official fix?

leeway1208 commented 2 years ago

Any update on when there will be an official fix?

I tried to fix it yesterday. You can update the latest version.

mnich0ls commented 2 years ago

Any update on when there will be an official fix?

I tried to fix it yesterday. You can update the latest version.

I updated to 2.0.7 and this issue is resolved for me. Thank you!