-
Notifications
You must be signed in to change notification settings - Fork 44
Description
I noticed that messages written by the Node process before exiting are sometimes lost. After some debugging I found an issue in the OutputThreadStart and ErrorThreadStart methods.
These methods append data read from the process output to a StringBuilder using TryCreateMessage. When the node process exits a "null" object is read. TryCreateMessage explicitly handles this "null" case and flushes the remaining data in the StringBuilder returning true. However the loop in the OutputThreadStart and ErrorThreadStart never call TryCreateMessage with "null" as the check is part of the while condition. Therefore any remaining characters in the StringBuilder are simply lost.
Another potential issue I noticed is that WaitForExitAsync is only called after process.Kill in DisposeAsyncCore, but not if the process has already Exited. Microsoft mentions calling WaitForExitAsync however to make sure that all output from the process it flushed (see remarks):
https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.waitforexit?view=net-8.0#system-diagnostics-process-waitforexit
I'm going to send a PR that adresses both issues.