-
Notifications
You must be signed in to change notification settings - Fork 466
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
-[MQTTDecoder stream:handleEvent:] crashing with EXC_BAD_ACCESS KERN_INVALID_ADDRESS #325
Comments
The one time so far I've managed to reproduce this on an Xcode debug, I got the following as the tail of the console log. I added one more debug print on line 130 of MQTTDecoder.m to print the
|
I have met the same issue, any update? |
Same issue, how is this going? |
the What broker are you using? It seems the broker is sending mosquitto debug messages to the mqtt connection. This is not MQTT protocol. The protocol violation is detected. The crash is probably caused by data already received which shouldn't be processed anymore after detecting the protocol violation |
Hi @ckrey and sorry for the late reply — the backend is using Mosquitto (https://github.com/toke/docker-mosquitto) as far as I know. I will try to find out more once the backend developers are back from vacations :) Strangely this bug peaked in the analytics at the latter half of June, then was mostly gone for most of July, until another peak over the very last few days. App usage has been quite constant over this period so it's a bit puzzling what exactly is causing it. |
I have same issue on my side. Also i use Mosquito broker on other side. Do you have update or advice what to do? |
I might have figured out why this happened. I called |
Still saw the same crash at least once (though only on a non-debug build so far) despite the fix mentioned above. But it seems to happen much more rarely now, if anything. |
Update: The "fix" I mentioned above didn't end up solving the problem, and if anything we actually saw the crashes peak over the past week or two. The root cause of the problem definitely seems to be some garbage (Mosquitto debug logs) being pushed into the pipeline by the backend (unfortunately I can't do anything about that). I tried a couple of other iOS MQTT client libraries and they actually dealt way worse with this problem, crashing right away when connecting, or never managing to parse any data. However, it seems – and this still needs more data points to make sure but at 40% adoption and zero crashes so far, it sure looks promising – that my latest update got rid of the crashes simply by holding onto each |
Yes, this time the crashes definitely seem to be gone for good. Still zero crashes reported for the newest app version after five days (we used to have at least a dozen every day). |
I have the same crash in Fabric. Any updates on this? @repomies |
@pablogeek yes, looks like in my case it completely disappeared after I deployed the fix described above – just holding onto the |
@repomies I am also facing the same issue. How do you hold the session after disconnection? A sample code would help. Thanks. |
Can you describe what you are doing with MQTT? Are you subscribing to a topic with a lot of large retained messages and QoS0, which causes the broker to flood the client with data? I do not want to say the library is error-free, but under "normal" circumstances it does behave quite stable |
@ckrey While the application is moving to background, I close the connection to the MQTT server its an Azure IoT Hub. While coming back to foreground, I try to connect to MQTT server again. Once in a couple of days the crash appears.
|
Relevant probably: |
I believe this bug is fixed on master: We had to move to using queues instead of run loop which is probably better anyway. There are some bits to resolve before making official release, but feel free to try it out from master. |
Ok, 0.10.0 version is on CocoaPods and this issue should be fixed I believe. Please give it a try. |
This is related to previous crash: #325
Using MQTTClient 0.12.0, still many crashes like this for my app, [MQTTDecoder stream:handleEvent:] @jcavar |
Do you have any idea how it happens? |
I think the crash is related to a synchronization issue in if (self.queue != dispatch_get_specific(&QueueIdentityKey)) {
dispatch_sync(self.queue, ^{ // deadlock
[self internalClose];
});
} Existing implementation seems to relay on the assumption that two different queues cannot perform blocks on the same thread. This assumption is not correct as GCD may skip switching threads when it's applicable (for performance reasons). Here is a test that should reproduce it. #import <XCTest/XCTest.h>
#import "MQTTDecoder.h"
@interface MQTTDecoderTests : XCTestCase
@end
@implementation MQTTDecoderTests
- (void)testCloseFromNonMainDispachQueueOnMainThread {
MQTTDecoder *sut = [[MQTTDecoder alloc] init];
dispatch_queue_t customQueue = dispatch_queue_create("mqttdecodertests.queue", nil);
dispatch_sync(customQueue, ^{
[sut close];
});
XCTAssertTrue(YES); // test passed if this line is reached
}
@end The fix is not trivial as the - (void)close {
BOOL dispatchedOnDecoderQueue = self.queue == dispatch_get_specific(&QueueIdentityKey);
BOOL calledOnMainThreadAndDecoderUsingMainQueue = [NSThread isMainThread] && self.queue == dispatch_get_main_queue();
BOOL canSafelyInlineInternalClose = dispatchedOnDecoderQueue || calledOnMainThreadAndDecoderUsingMainQueue;
if (!canSafelyInlineInternalClose) {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"Cannot close MQTTDecoder synchronously"
userInfo:nil];
}
[self internalClose];
} Maybe we could improve the fix by replacing the exception with a code niling the delegate and dispatching |
This is still happen because QueueIdentityKey = NULL. I have fixed by this way, and it works.
|
We merged this a while ago I think. Is this issue still happening? |
I’m sorry I can’t answer for myself, since our app’s backend infrastructure unfortunately no longer exists. |
This issue also happened in my application lately, using version 0.15.2 |
Can you provide more information about how it happens (logs, conditions, steps)? |
This is related to previous crash: novastone-media#325
Crashed: com.apple.main-thread Still we are getting this crash in iOS |
I think should avoid doing some potentially risky things in the dealloc method. |
Over the past days I've seen a few crashes like this for my app in Crashlytics. Any ideas what might be going wrong? Using MQTTClient 0.9.2.
The text was updated successfully, but these errors were encountered: