From ae47a97d0f4b20017cfa7c10077f900362c5eb6a Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Mon, 9 Dec 2024 22:09:47 +0300 Subject: [PATCH 1/5] 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 e41ff385..b7c5239b 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 @@ -903,7 +903,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 + } } } }; From 03bd370a5c816c9d2a9683db0600a40129e5f801 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Mon, 9 Dec 2024 23:01:34 +0300 Subject: [PATCH 2/5] Use content length to set a mark before attempting the reset --- .../java/com/microsoft/kiota/http/OkHttpRequestAdapter.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 b7c5239b..bac90d01 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 @@ -901,9 +901,15 @@ public long contentLength() throws IOException { @Override public void writeTo(@Nonnull BufferedSink sink) throws IOException { + // stored in variable before writing to the sink due to + // available()'s definition + long contentLength = contentLength(); sink.writeAll(Okio.source(requestInfo.content)); if (!isOneShot()) { try { + if (contentLength > 0) { + requestInfo.content.mark((int) contentLength); + } requestInfo.content.reset(); } catch (Exception ex) { spanForAttributes.recordException(ex); From 7e0e06481dd11f62ad6363145147c3de6090a9f9 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Mon, 9 Dec 2024 23:34:53 +0300 Subject: [PATCH 3/5] Set a mark at the beginning of the stream before reading it --- .../java/com/microsoft/kiota/http/OkHttpRequestAdapter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 bac90d01..2a9e425a 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,12 +904,12 @@ public void writeTo(@Nonnull BufferedSink sink) throws IOException { // stored in variable before writing to the sink due to // available()'s definition long contentLength = contentLength(); + if (contentLength() > 0) { + requestInfo.content.mark((int) contentLength); + } sink.writeAll(Okio.source(requestInfo.content)); if (!isOneShot()) { try { - if (contentLength > 0) { - requestInfo.content.mark((int) contentLength); - } requestInfo.content.reset(); } catch (Exception ex) { spanForAttributes.recordException(ex); From 4ab1087936287666f3e6abfd95c86a7e9b744368 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Mon, 9 Dec 2024 23:39:52 +0300 Subject: [PATCH 4/5] Remove comment --- .../java/com/microsoft/kiota/http/OkHttpRequestAdapter.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 2a9e425a..8b6a2f28 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 @@ -901,10 +901,8 @@ public long contentLength() throws IOException { @Override public void writeTo(@Nonnull BufferedSink sink) throws IOException { - // stored in variable before writing to the sink due to - // available()'s definition long contentLength = contentLength(); - if (contentLength() > 0) { + if (contentLength > 0) { requestInfo.content.mark((int) contentLength); } sink.writeAll(Okio.source(requestInfo.content)); From 1b9784f59977f0e5191c09821442034f30544f53 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Thu, 19 Dec 2024 19:18:54 +0300 Subject: [PATCH 5/5] chore: release 1.8.2 Release-As: 1.8.2