This is a duplicate of #7555. But please don't close without having a close look.
I claim, that the bug still persists.
The Problem is systematic, since the autoselect relies on a state that was defined in the past and does not react on state changes in the meantime. So it is not "serializable"
I try to explain the race condition:
1 = async thread 1
2 = async thread 2
This happens sequentially as listed:
1 waiting 300ms (default delay)
1 AJAX request is triggered
2 Before ajax is finished, I type "a"
2 ... "a" triggers just nothing, because 300ms have not timed out ...
1 AJAX call returns
1 Autoselect selects the first hit (search term 'jav') and fills the input field with 'jav'
Where is my 'a'??
I could reproduce this behaviour in 1.8.16 and 1.9m6
My solution suggestion:
Implement a proper debouncing mechanism!
1. Each time I press a key, the delay timeout should be cleared. Why? A search request should only be started after i havent presse a key for $delay ms. If i got it right you set a timeout for EACH keydown and don't clear the old timeout.
2. If a AJAX request (or generally speaking a source lookup) is ongoing and I change the state of the input (e.g. by pressing a key). The request should be cancelled immediately and not after $delay