fix(miner): close the xmrig stdout fd after the monitor join
Stopping the miner closed the stdout pipe before joining the monitor thread, and the UI thread's stats poll also drained stdout. Either path could read or close a descriptor the other side was still using, so a read could land on a closed or already-reused fd. - stop() now joins the monitor thread first and only then closes the process handle and the stdout pipe, so nothing is draining the pipe when it is closed. - The stdout drain is serialized under its own mutex, and the UI thread's stats poll no longer drains stdout at all: the monitor thread is the sole reader. The process handle, pid and fds are atomic so they can be observed safely from the memory probe. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -177,12 +177,13 @@ private:
|
||||
|
||||
// Process handles
|
||||
#ifdef _WIN32
|
||||
HANDLE process_handle_ = nullptr;
|
||||
HANDLE stdout_read_ = nullptr;
|
||||
std::atomic<HANDLE> process_handle_{nullptr};
|
||||
std::atomic<HANDLE> stdout_read_{nullptr};
|
||||
#else
|
||||
pid_t process_pid_ = 0;
|
||||
int stdout_fd_ = -1;
|
||||
std::atomic<pid_t> process_pid_{0};
|
||||
std::atomic<int> stdout_fd_{-1};
|
||||
#endif
|
||||
std::mutex io_mutex_; // serializes drainOutput(); lock order io_mutex_ -> output_mutex_
|
||||
|
||||
std::thread monitor_thread_;
|
||||
std::atomic<bool> should_stop_{false};
|
||||
|
||||
Reference in New Issue
Block a user