process: do not return nil until process exited #1973
Merged
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.
This is a very weird Windows-specific regression.
Currently, when we call read_stdout or read_stderr repeatedly, the function returns these three distinct results:
"<data>"
: We read something""
: There is no data available / stream is closed (EOF)This is a weird status quo, but well, killing the process when stream closes is not good, and I am not here to rethink the design.
On Windows, this is not the case due to how ReadFile and OVERLAPPED IO works.
On Linux:
On Windows:
The code is somewhat equivalent, but on Windows OVERLAPPED IO operates on completion, so one can think of GetOverlappedResult() and ReadFile() can be merged into a single operation here. For that reason, the synchronous read branch is not shown.
The problem lies in (5) and (6). When (5) fails with ERROR_EOF_HANDLE, Lite XL ignores this error code and pretends that it does a 0-size read. That's fine. But when (6) comes around, Lite XL thought that some other error has occured and kills the program. This is not the case on Linux:
lite-xl/src/api/process.c
Lines 631 to 639 in 36db156
On Linux, we only kill the process if we hit an actual pipe error, we never kill the process because we hit EOF. When we hit EOF, we continue to return an empty string until the process dies.
On Windows:
lite-xl/src/api/process.c
Lines 609 to 626 in 36db156
The Windows code is really terse and hard to read, but the takeaway is the code will kill the process no matter what happened, as long as it didn't read a thing, like EOF. The function also don't return an empty string until the process actually dies, it also doesn't call
poll_process()
which causes an edge case of callingprocess:returncode()
right afterread_stdout()
fails to not work.This PR emulates the POSIX behavior of calling poll_process when we hit EOF. This will fix the aforementioned edge case, and returns an empty string until the process actually exits.