edubkendo / atom-racer

Intelligent code completion for Rust in the Atom Editor. Requires Racer.
MIT License
115 stars 24 forks source link

only care about latest process - avoid race conditions #56

Closed rovjuvano closed 8 years ago

rovjuvano commented 8 years ago

Multiple racer processes get spawned simultaneously which leads to race conditions: 1) the winning process deletes the temp files of the other processes causing file not found exceptions 2) the winning process may display results out of sync with the on screen text to autocomplete

e.g. Given line use std::io::, type Bu. Two temp files get created along with two racer processes. If the B-process finishes first, its results are offered, both temp files get deleted, and the u-process throws an exception. Thus, results which do not match like Bytes get displayed. Because it's a race condition, the behavior is inconsistent. Sometimes no exception gets thrown. Sometimes the u results get displayed.

This issue makes the package nearly unusable under my dockerized setup.

The current implementation gives preference to the first response (which would usually be the first request). If it weren't for the temp files getting deleting, it would give preference to the last response, which would usually but not always be the last the request. This change enforces that only the last request matters (i.e. the one that matches the latest on screen text to autocomplete) and it greatly narrows the window in which the temp file cleanup will throw an exception.

Ideally, we would have debounce, dedup, and latest request. This adds latest request.

edubkendo commented 8 years ago

yup that sounds like a pretty nasty race condition. Thank you for contributing.