-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
Crash in RTCPeerConnection.close() #161
Comments
Well, I mean this: func RTCPeerConnection_close(command: CDVInvokedUrlCommand) {
NSLog("iosrtcPlugin#RTCPeerConnection_close()")
let pcId = command.argumentAtIndex(0) as! Int
var pluginRTCPeerConnection = self.pluginRTCPeerConnections[pcId]
if pluginRTCPeerConnection == nil {
NSLog("iosrtcPlugin#RTCPeerConnection_close() | ERROR: pluginRTCPeerConnection with pcId=%@ does not exist", String(pcId))
return;
}
dispatch_async(self.queue) {
pluginRTCPeerConnection!.close()
pluginRTCPeerConnection = nil
}
// Remove the pluginRTCPeerConnection from the dictionary.
self.pluginRTCPeerConnections[pcId] = nil
} |
I've committed the above code to avoid the crash, but I understand this must be re-checked. |
@saghul even with the fix you got a crash? I am going to test this now also here |
With the already applied commit I don't get the crash. |
@ibc i'm sorry I think I forgot to modify that function in my previous PR. Would this work? Perhaps the problem is because when you do |
Oh, and make sure you do [weak pluginRTCPeerConnection, unowned self] |
I tested master a few hours ago, will test it again shortly.
|
Tested again, with latest master and everything works as expected, great work everyone! 😍 |
Same here, no issues! Thanks for the work! |
@saghul @mark-veenstra, current master was "fixed" by me yesterday so it does not crash, but as @oNaiPs said above some changes most be done for the PeerConnection to be released. |
@oNaiPs wouldn't also need dispatch_async(self.queue) { [weak pluginRTCPeerConnection] in
pluginRTCPeerConnection?.createOffer(options,
callback: { (data: NSDictionary) -> Void in
self.emit(command.callbackId,
result: CDVPluginResult(status: CDVCommandStatus_OK, messageAsDictionary: data as [NSObject : AnyObject])
)
},
errback: { (error: NSError) -> Void in
self.emit(command.callbackId,
result: CDVPluginResult(status: CDVCommandStatus_ERROR, messageAsString: error.localizedDescription)
)
}
)
} I expect that given that |
@oNaiPs I've committed right now a fix following your suggestions, may you please check it? I've tested it and it does not crash. However I do not understand why I must pass dispatch_async(self.queue) { [weak pluginRTCPeerConnection, unowned self] in
pluginRTCPeerConnection!.close()
// Remove the pluginRTCPeerConnection from the dictionary.
self.pluginRTCPeerConnections[pcId] = nil
} At the end |
Swift: a better fix for cordova-rtc#161
You;re right, you don't have to. CDVPlugin is not going to be deallocated anyways. |
We still encounter (sometimes) a crash in this close. |
I have been testing this fix for a while on an iPhone 5 with 9.3.1 and it no longer crashed. |
Thanks @jgsacris |
Unfortunately we are continuing to get a crash, even with the new code implemented. Same place as OP.
Our configuration is as follows |
@jpkolind We are also encountering same issue, but when we change the code as follows it works like a charm:
|
@mark-veenstra I think the crash can only happen if close it called twice. Since the actual close happens asynchronously, it's possible for close to be called twice and for the close to happen also on the Swift side. Now, if that happens, it's also possible that the first nil check is passed but the object becomes nil in the async block, so the fix LGTM. Can you please send a PR? |
Thank you! That worked perfectly. |
After merging #159 (so cordova-ios 4 is used) and #160, calling
peerConnection.close()
crashes with:It does not crash as follows:
I've also tried passing
[weak pluginRTCPeerConnection] in
todispatch_async()
but it crashes as well, so I'm worried whether the native object is not properly deallocated.If so, would this work?
/cc @oNaiPs
The text was updated successfully, but these errors were encountered: