Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25836] iOS: Using "run-on-main-thread", multiple global event listeners do not work

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2018-05-21T11:58:48.000+0000
Affected Version/sRelease 7.1.0, Release 7.0.2
Fix Version/sRelease 7.3.0
ComponentsiOS
Labelsios
ReporterAndreas Pingas
AssigneeVijay Singh
Created2018-03-02T15:29:49.000+0000
Updated2018-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

FileDateSize
app.js2018-03-03T22:37:23.000+0000394

Comments

  1. Sharif AbuDarda 2018-03-03

    Hello, Please provide a sample reproducible test project for us to test. Thanks.
  2. Andreas Pingas 2018-03-03

    [^app.js]
  3. Hans Knöchel 2018-03-04

    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
  4. Andreas Pingas 2018-03-04

    Sorry about the caps, thank you for your reply!
  5. Hans Knöchel 2018-03-05

    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.
  6. Vijay Singh 2018-03-06

    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.
  7. Vijay Singh 2018-03-06

    PR - https://github.com/appcelerator/titanium_mobile/pull/9908
  8. Samir Mohammed 2018-06-26

    *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

    TestCheckNetwork Was fired and could be seen in the console

    *Test Environment*
       APPC Studio: 5.0.0.201712081732
       APPC CLI: 7.0.4
       iphone 6 (11.2) Emulator
       Operating System Name: Mac OS High Sierra
       Operating System Version: 10.13
       Node.js Version: 8.9.1
       Xcode 9.2
       

JSON Source