Fix the waiting system

Not having the lock doesn't necessarily means that the waiting time
should be reset.
Merge branch 'master' into search-1.3.x