[TIMOB-25836] iOS: Using "run-on-main-thread", multiple global event listeners do not work
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-05-21T11:58:48.000+0000 |
Affected Version/s | Release 7.1.0, Release 7.0.2 |
Fix Version/s | Release 7.3.0 |
Components | iOS |
Labels | ios |
Reporter | Andreas Pingas |
Assignee | Vijay Singh |
Created | 2018-03-02T15:29:49.000+0000 |
Updated | 2018-06-26T20:55:30.000+0000 |
Description
The following:
var functionA = function(arg) {
Ti.App.removeEventListener('TestCheckNetwork', functionA);
};
var functionB = function(arg) {
Ti.App.removeEventListener('TestCheckNetwork', functionB);
};
Ti.App.addEventListener('TestCheckNetwork', functionA);
Ti.App.addEventListener('TestCheckNetwork', functionB);
Ti.App.fireEvent('TestCheckNetwork');
If main-thread is enabled:
<property name="run-on-main-thread" type="bool">true</property>
There is the following issue:
[ERROR] : Script Error {
[ERROR] : column = 17;
[ERROR] : line = 511;
[ERROR] : message = "*** Collection <__NSArrayM: 0x608000049ea0> was mutated while being enumerated.";
[ERROR] : sourceURL = "";
[ERROR] : }
[ERROR] : ErrorController is up. ABORTING open
Attachments
File | Date | Size |
---|---|---|
app.js | 2018-03-03T22:37:23.000+0000 | 394 |
Hello, Please provide a sample reproducible test project for us to test. Thanks.
[^app.js]
Please do not use caps in the ticket title and description. It does not help and rather produces the opposite. We will consider looking into it, although it looks like an app issue with duplicate event listeners
Sorry about the caps, thank you for your reply!
After taking a peak on this, I am not feeling confident that this should be fixed, although it might be a breaking change coming from the kroll thread. The reason for the error is that your are removing event listeners concurrently, resulting in a race condition. Using the kroll thread, this was a non-issue, because the kroll-thread would just block the whole app, but using the (more performant) main thread, it does not anymore, resulting in this behavior. We will leave the ticket open for now for further investigations.
In my view, we should fix this. We have to just hold the array from where we are fetching the listener until we do not process all event firing.
PR - https://github.com/appcelerator/titanium_mobile/pull/9908
*Closing ticket.* Verified fix can be seen in SDK Version:
7.3.0.v20180625114905
*FR (Passed) Test Steps:*Created an application with the code mentioned in the description
Ran the program
Application no longer crashed
*Test Environment*TestCheckNetwork
Was fired and could be seen in the console