Skip to content

Commit 87dc6b8

Browse files
authored
Merge pull request #1696 from microsoft/fix/request-body-stream-reset
Handle exceptions when resetting streams after writing to the network
2 parents 81e521c + 2bf7173 commit 87dc6b8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,9 +901,21 @@ public long contentLength() throws IOException {
901901

902902
@Override
903903
public void writeTo(@Nonnull BufferedSink sink) throws IOException {
904+
long contentLength = contentLength();
905+
if (contentLength > 0) {
906+
requestInfo.content.mark((int) contentLength);
907+
}
904908
sink.writeAll(Okio.source(requestInfo.content));
905909
if (!isOneShot()) {
906-
requestInfo.content.reset();
910+
try {
911+
requestInfo.content.reset();
912+
} catch (Exception ex) {
913+
spanForAttributes.recordException(ex);
914+
// we don't want to fail the request if reset() fails
915+
// reset() was a measure to prevent draining the request
916+
// body by an interceptor before
917+
// the final network request
918+
}
907919
}
908920
}
909921
};

0 commit comments

Comments
 (0)