[TIMOB-27898] iOS: Race condition in setTimeout/clearTimeout (regression)
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2020-06-08T13:58:47.000+0000 |
Affected Version/s | Release 8.3.1, Release 9.1.0 |
Fix Version/s | Release 9.0.3 |
Components | iOS |
Labels | clearInterval, ios, race_condition, regression, setinterval |
Reporter | Hans Knöchel |
Assignee | Jan Vennemann |
Created | 2020-05-18T09:15:44.000+0000 |
Updated | 2020-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).
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.
I can reproduce with the following
PR (master): https://github.com/appcelerator/titanium_mobile/pull/11734 PR (9_0_X): https://github.com/appcelerator/titanium_mobile/pull/11735
merged to master for 9.1.0 target, 9_0_X for 9.0.3 target.
Verified changes in 9.0.3.v20200608051820 and 9.1.0.v20200604104832. Closing ticket.