Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebuild --watch event loop to simplify; fix concurrency issues #40

Merged
merged 3 commits into from
Aug 25, 2024

Conversation

mattbrictson
Copy link
Owner

Before, the watcher event loop relied on multiple threads and raised an exception to interrupt the main thread whenever a file system change event happened. This was messy and resulted in zombie processes and other weird behavior when a file system change was detected in the middle of running tests.

This commit refactors the implementation to use a new EventQueue class. It leverages the buffering inherent in stdin, plus uses a thread-safe queue for placing file system change events, and then "pops" the next of these in each iteration of the event loop.

To avoid starting a separate thread for reading key presses, the "pop" operation takes turns polling stdin (peeking at its buffer to see if a key press happened) and blocking for short period waiting for file system events.

The result is cleaner, easier to test, and not prone to the zombie process bug.

@mattbrictson mattbrictson added the 🐛 Bug Fix Fixes a bug label Aug 25, 2024
@mattbrictson mattbrictson force-pushed the redo-watcher-event-handling branch 2 times, most recently from 808dedc to 1e7e306 Compare August 25, 2024 15:27
Before, the watcher event loop relied on multiple threads and raised an
exception to interrupt the main thread whenever a file system change
event happened. This was messy and resulted in zombie processes and
other weird behavior when a file system change was detected in the
middle of running tests.

This commit refactors the implementation to use a new `EventQueue`
class. It leverages the buffering inherent in stdin, plus uses a
thread-safe queue for placing file system change events, and then "pops"
the next of these in each iteration of the event loop.

To avoid starting a separate thread for reading key presses, the "pop"
operation takes turns polling stdin (peeking at its buffer to see if a
key press happened) and blocking for short period waiting for file
system events.

The result is cleaner, easier to test, and not prone to the zombie
process bug.
@mattbrictson mattbrictson changed the title Rebuild --watch event loop to simplify, fix concurrency issues Rebuild --watch event loop to simplify; fix concurrency issues Aug 25, 2024
@mattbrictson mattbrictson merged commit 5bd7ef0 into main Aug 25, 2024
6 checks passed
@mattbrictson mattbrictson deleted the redo-watcher-event-handling branch August 25, 2024 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Fix Fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant