fix: prevent PTY output truncation by correctly handling EOF in cache_thread (#84) #85
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.
Fix Explanation
This logic is divided into two phases:
Data Acquisition Phase --> Data Output Phase
The idea is:
In the Data Acquisition Phase
If the data in
read_bufis sufficient, there is no need to fetch additional data fromreader_out_rx, and the data of the size specified by the user can be directly returned fromread_buf. Therefore, the acquisition phase returns an empty string.If the data in
read_bufis insufficient, additional data should be fetched fromreader_out_rx. Therefore, the acquisition phase returns the data taken fromreader_out_rx.If
reader_out_rxreturnsNone, an empty string can be returned first, delaying the throwing of theStandard out reached EOFexception to the Data Output Phase.In the Data Output Phase
Merge the data returned from the Data Acquisition Phase into
read_buf, and return as much data as possible based on the user's request, without exceeding the size specified by the user.Before returning the data, if it is found that:
reader_out_rxhas returned None (indicating that the current state is EOF)Then throw the
Standard out reached EOFexception.Otherwise, return the prepared data.
Other Notes
I am not familiar with the Rust language, having only seen Rust code for the first time three days ago. I can only understand Rust code with the help of GPT. Therefore, my modifications may have issues, and I hope you can review and test them in detail.