From a1ecc42d9f9214e8b2289a226861f6e6eb47fc4f Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Mon, 9 Dec 2024 22:09:47 +0300 Subject: [PATCH] fix: Handle failure to reset request body streams after writing request body --- .../com/microsoft/kiota/http/OkHttpRequestAdapter.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java index b634cf7da..7083b3644 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java @@ -904,7 +904,15 @@ public long contentLength() throws IOException { public void writeTo(@Nonnull BufferedSink sink) throws IOException { 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 + } } } };