fix: run hangs on child exit#19
Merged
Merged
Conversation
Signed-off-by: Mauro Lacy <11656534+maurolacy@users.noreply.github.com>
Signed-off-by: Mauro Lacy <11656534+maurolacy@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses a hang in watch mode by unifying file-system watcher events and runner lifecycle notifications onto a single channel, allowing the main loop to react when the child process (or runner thread) terminates.
Changes:
- Introduces a
WatchEventchannel to handle both notify events and child-exit notifications in one event loop. - Updates
cargo_run_loopto proactively notify the main thread when the child exits (or fails to spawn) so watch mode can stop cleanly. - Adds a regression unit test for the spawn-failure case.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| enum WatchEvent { | ||
| /// A file-system event from the watcher. | ||
| Fs(Result<notify::Event, notify::Error>), | ||
| /// The child process exited on its own (not killed by a signal). |
Comment on lines
+242
to
260
| #[test] | ||
| fn runner_sends_child_exited_on_spawn_failure() { | ||
| let (_signal_tx, signal_rx) = mpsc::channel::<RunSignal>(); | ||
| let (event_tx, event_rx) = mpsc::channel::<WatchEvent>(); | ||
|
|
||
| // Non-existent directory causes spawn() to fail. | ||
| let cargo_dir = PathBuf::from("/nonexistent/cargo/dir"); | ||
| let config_path = PathBuf::from("/nonexistent/config.yml"); | ||
|
|
||
| let handle = std::thread::spawn(move || { | ||
| cargo_run_loop(&cargo_dir, &config_path, &signal_rx, &event_tx); | ||
| }); | ||
|
|
||
| let event = event_rx | ||
| .recv_timeout(Duration::from_secs(5)) | ||
| .expect("should receive ChildExited within timeout"); | ||
| assert!(matches!(event, WatchEvent::ChildExited)); | ||
| handle.join().expect("runner thread should not panic"); | ||
| } |
Bechma
approved these changes
Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.