fix: flush remaining OpenOCD log lines after process exits#14
Merged
Conversation
run_command_sender's drain-and-poll loop forwarded mutex contents to the sender, then checked try_wait() — if the child had exited it joined the reader threads and broke out without one last drain. Race: between the last lock/clear and the moment try_wait() returns Some(...), the reader threads can still push lines. Joining the threads guarantees they're done pushing, but those last messages stay in the mutex and are never forwarded. This is exactly when OpenOCD emits the diagnostic line that explains why a flash failed — and it was disappearing from the in-app log. Add a final drain after `thread_stdout.join()` / `thread_stderr.join()` and before `break`. Extracted the drain into a small closure so the loop body and the post-exit pass share the same logic. Closes #9.
There was a problem hiding this comment.
Pull request overview
Ensures the UI receives the final OpenOCD log lines emitted right before process termination by performing one last post-exit drain after the stdout/stderr reader threads have been joined.
Changes:
- Refactors the message-queue drain logic into a small reusable closure.
- Adds a final drain-and-forward pass after
try_wait()reports exit and the reader threads are joined, preventing last-moment log loss.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Closes #9.
run_command_senderpolls the OpenOCD child process and drains queued log lines into the in-app sender. Between the last in-loop drain and the momenttry_wait()returnsSome(...), the reader threads can still push lines into the mutex. After joining the threads (which guarantees they're done writing) the loop broke out without one last drain — those final messages stayed in the mutex and were silently dropped from the UI.That's exactly when OpenOCD emits the diagnostic that explains why a flash failed (
** Error: target halted unexpectedly,** verification failed**, transport errors, etc.). Users were seeing a genericExit code: 1with no context.This PR extracts the drain into a tiny closure shared by the polling loop and a new post-exit pass, run after the reader threads are joined and before
break. No behavior change in the success path.Test plan
Timer::afteris unchanged.