Skip to content

Commit

Permalink
Merge pull request #1696 from microsoft/fix/request-body-stream-reset
Browse files Browse the repository at this point in the history
Handle exceptions when resetting streams after writing to the network
  • Loading branch information
Ndiritu authored Dec 19, 2024
2 parents 81e521c + 2bf7173 commit 87dc6b8
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,21 @@ public long contentLength() throws IOException {

@Override
public void writeTo(@Nonnull BufferedSink sink) throws IOException {
long contentLength = contentLength();
if (contentLength > 0) {
requestInfo.content.mark((int) contentLength);
}
sink.writeAll(Okio.source(requestInfo.content));
if (!isOneShot()) {
requestInfo.content.reset();
try {
requestInfo.content.reset();
} catch (Exception ex) {
spanForAttributes.recordException(ex);
// we don't want to fail the request if reset() fails
// reset() was a measure to prevent draining the request
// body by an interceptor before
// the final network request
}
}
}
};
Expand Down

0 comments on commit 87dc6b8

Please sign in to comment.