flush-macos-patch: Always flush after write on MacOS #159
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.
Changes proposed in this PR.
We edited the
writemethod to always flush on MacOS.Reason for this proposal.
I'm a volunteer for The Tor Project contributing to Arti. We implement a custom struct
DataStreamused as underlying internal stream bytokio-native-tls,DataStreamimplements an internal buffering mechanism (see here) .Internal buffering was a conscious design choice to improve performance, but due to this we consistently get the error
Error: connection closed via error.whennative-tlsis used on MacOS. I suspect this has something to do withnative-tlsusing Apple's deprecated Secure Transport API which is very limited.Making sure the internal stream is always flushed after a
writemakes this crate work consistent again.This change is not ideal, but I guess it's required to make
tokio-native-tlswork stable for MacOS with more complex internal streams due to Secure Transport's limited API and deprecated state.Reproduce
When running the following test code (click here) on MacOS you'll consistently get the error
Error: connection closed via error. This because this minimal reproduction also implements an internal buffering mechanism.Edit the
Cargo.tomlof that example to implement this fork (and the changes in this PR) as patch and it will work consistently.Context
Extra context for this MR: