Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27898] iOS: Race condition in setTimeout/clearTimeout (regression)

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2020-06-08T13:58:47.000+0000
Affected Version/sRelease 8.3.1, Release 9.1.0
Fix Version/sRelease 9.0.3
ComponentsiOS
LabelsclearInterval, ios, race_condition, regression, setinterval
ReporterHans Knöchel
AssigneeJan Vennemann
Created2020-05-18T09:15:44.000+0000
Updated2020-09-01T08:27:25.000+0000

Description

There seem to be a critical regression regarding intervals in SDK 8 and 9 (so maybe caused between SDK 7 and 8?). See the following vanilla Node.js test case for reference (using a classic throttling mechanism):
let searchTimeout;

function search(value) {
	if (searchTimeout) {
		console.warn('Abort request');
		clearTimeout(searchTimeout);
	}

	searchTimeout = setTimeout(() => {
        console.warn('Start search: ' + value);
	}, 500);
}

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

(async function () {
    search('m');
    search('me');
    search('mep');
}());
The expected console output is:
Abort request
Abort request
Start search: mep
But on iOS, the kroll timer manager has different plans with us:
Abort request
Start search: m
Start search: mep
Here is the app test case (wrapped into a quick i/o UI):
let searchTimeout;

function search(value) {
	if (searchTimeout) {
		console.warn('Abort request');
		clearTimeout(searchTimeout);
	}

	searchTimeout = setTimeout(() => {
        console.warn('Start search: ' + value);
	}, 500);
}

var win = Ti.UI.createWindow({
    backgroundColor: '#fff'
});

var btn = Ti.UI.createButton({
    title: 'Test'
});

btn.addEventListener('click', function onClick() {
    search('m')
    search('me')
    search('mep')
});

win.add(btn);
win.open();
Notably, iOS does something wrong here. And Android works just fine (like Node.js).

Comments

  1. Hans Knöchel 2020-05-19

    Can this please be validated on the team side? It's an absolute blocker as it caused multiple parts of our app to behave randomly incorrectly.
  2. Rene Pot 2020-05-19

    I can reproduce with the following
       SDK 9.0.1.GA
       appc CLI 8.0.0
       Ti CLI 5.2.2
       iOS 13.4 Simulator (iPhone 11)
       xcode 11.4.1
       
  3. Jan Vennemann 2020-05-26

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/11734 PR (9_0_X): https://github.com/appcelerator/titanium_mobile/pull/11735
  4. Christopher Williams 2020-06-04

    merged to master for 9.1.0 target, 9_0_X for 9.0.3 target.
  5. Ewan Harris 2020-06-08

    Verified changes in 9.0.3.v20200608051820 and 9.1.0.v20200604104832. Closing ticket.

JSON Source