Skip to content

StandardOut and StandardError are not properly read #165

@aKzenT

Description

@aKzenT

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions