Fix sporadic ansible-runner macOS bug and remove extra listener thread #23229
+27
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It was found that on macOS a sporadic failure would occur where the internal listener, while started, wouldn't actually start listening right away, causing the listener to miss the file we were waiting for.
The listen gem creates an internal thread,
@run_thread
, which on most target systems is where the actually listening is done. However, on macOS,@run_thread
creates a second thread,@worker_thread
, which does the actual listening. It's possible that although the listener is started, the@worker_thread
hasn't actually started yet. This leaves a window where the target_path we are waiting on can actually be created before the@worker_thread
is started and we "miss" the creation of the target_path. This commit ensures that we won't move on until that thread is ready, further ensuring we can't miss the creation of the target_path.Ansible::Runner#wait_for was also creating an extra thread when starting the listener, but this thread is unnecessary as the listen gem creates its own internal thread under the covers.
@agrare Please review. I'd also like it if you could verify this on linux, since the removal of that extra thread could affect that path. I'm concerned that while macOS has this special case, there might be a different, but similar, special case on Linux we need to account for after calling
listener.start
.I've also considering opening a bug in the upstream listen gem but would like your thoughts. IMO,
listener.start
shouldn't return until the underlying watching has actually started.