Surface write failures through [flush] #217
Draft
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.
Currently, if you are writing to a body in a streaming manner, and the writer becomes closed, then you have to be careful to not write any more to the body. In practice this can be hard to achieve because your application-level code is probably the one writing to the body and your runtime / network-level code is the one that calls
report_write_result `Closed
.This PR therefore makes it safe to write to a body after the attached writer is closed. Those writes are simply ignored.
The user has two ways of discovering whether their writes are actually going to be processed or not:
Body.is_closed
, which now returns true if we've detected that the attached writer is closed, in addition to returning true ifBody.closed
has been called.Body.flush
has been augmented so that the callback is told whether the bytes successfully made it out of the writer, or were dropped on the floor. I.e. it has typeval Body.flush : Body.t -> ([ `Closed | `Written ] -> unit) -> unit
.