Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload file to Sharepoint failed with 'Stream mark expired' when the inputstream is markSuppoted #2245

Open
ihudedi opened this issue Dec 3, 2024 · 3 comments · May be fixed by microsoft/kiota-java#1696
Labels
type:bug A broken experience

Comments

@ihudedi
Copy link

ihudedi commented Dec 3, 2024

Describe the bug

Hi,
When trying to upload file to sharepoint using
graphServiceClient.drives().byDriveId(driveId).items().byDriveItemId(getDriveItemIdFromRootPath(filePath)).content().put(fileContent);
Getting this exeception if the inputstream has markSupported
java.lang.RuntimeException: Stream mark expired.
at com.azure.storage.common.StorageInputStream.reset(StorageInputStream.java:396) [azure-storage-common-12.27.1.jar!/:12.27.1]
at com.microsoft.kiota.http.OkHttpRequestAdapter$1.writeTo(OkHttpRequestAdapter.java:907) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:62) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.RetryHandler.intercept(RetryHandler.java:226) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.RedirectHandler.intercept(RedirectHandler.java:158) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.HeadersInspectionHandler.intercept(HeadersInspectionHandler.java:70) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.UrlReplaceHandler.intercept(UrlReplaceHandler.java:52) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.ParametersNameDecodingHandler.intercept(ParametersNameDecodingHandler.java:79) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.UserAgentHandler.intercept(UserAgentHandler.java:84) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.graph.core.requests.middleware.GraphTelemetryHandler.intercept(GraphTelemetryHandler.java:64) [microsoft-graph-core-3.3.1.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.UrlReplaceHandler.intercept(UrlReplaceHandler.java:72) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.OkHttpRequestAdapter.getHttpResponseMessage(OkHttpRequestAdapter.java:716) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:275) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at com.microsoft.graph.drives.item.items.item.content.ContentRequestBuilder.put(ContentRequestBuilder.java:103) [microsoft-graph-6.20.0.jar!/:?]

If you go to OkHttpRequestAdapter you can see that when building the RequestBody there is method:
@OverRide
public void writeTo(@nonnull BufferedSink sink) throws IOException {
sink.writeAll(Okio.source(requestInfo.content));
if (!isOneShot()) {
requestInfo.content.reset();
}
}
This cause the upload failed.
Do you know why you reset this 2 times I saw in this file.
Thanks,
Itay

Expected behavior

Upload file should be suuceeded with inputstream with markSupported

How to reproduce

Hi,
When trying to upload file to sharepoint using
graphServiceClient.drives().byDriveId(driveId).items().byDriveItemId(getDriveItemIdFromRootPath(filePath)).content().put(fileContent);
Getting this exeception if the inputstream has markSupported
java.lang.RuntimeException: Stream mark expired.
at com.azure.storage.common.StorageInputStream.reset(StorageInputStream.java:396) [azure-storage-common-12.27.1.jar!/:12.27.1]
at com.microsoft.kiota.http.OkHttpRequestAdapter$1.writeTo(OkHttpRequestAdapter.java:907) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:62) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.RetryHandler.intercept(RetryHandler.java:226) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.RedirectHandler.intercept(RedirectHandler.java:158) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.HeadersInspectionHandler.intercept(HeadersInspectionHandler.java:70) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.UrlReplaceHandler.intercept(UrlReplaceHandler.java:52) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.ParametersNameDecodingHandler.intercept(ParametersNameDecodingHandler.java:79) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.UserAgentHandler.intercept(UserAgentHandler.java:84) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.graph.core.requests.middleware.GraphTelemetryHandler.intercept(GraphTelemetryHandler.java:64) [microsoft-graph-core-3.3.1.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.UrlReplaceHandler.intercept(UrlReplaceHandler.java:72) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.OkHttpRequestAdapter.getHttpResponseMessage(OkHttpRequestAdapter.java:716) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:275) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at com.microsoft.graph.drives.item.items.item.content.ContentRequestBuilder.put(ContentRequestBuilder.java:103) [microsoft-graph-6.20.0.jar!/:?]

If you go to OkHttpRequestAdapter you can see that when building the RequestBody there is method:
@OverRide
public void writeTo(@nonnull BufferedSink sink) throws IOException {
sink.writeAll(Okio.source(requestInfo.content));
if (!isOneShot()) {
requestInfo.content.reset();
}
}
This cause the upload failed.
Do you know why you reset this 2 times I saw in this file.
Thanks,
Itay

SDK Version

6.22.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_
@ihudedi ihudedi added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Dec 3, 2024
@ihudedi
Copy link
Author

ihudedi commented Dec 8, 2024

Hi @baywet
Do you know what the issue is?
Thanks,
Itay

@Ndiritu Ndiritu removed the status:waiting-for-triage An issue that is yet to be reviewed or assigned label Dec 9, 2024
@Ndiritu
Copy link
Contributor

Ndiritu commented Dec 9, 2024

Hi @ihudedi
Apologies for the slow response here.
Thank you for reporting this. I can confirm that this is a bug in our implementation.

We did not handle the case where an exception may be thrown based on the method definition for reset. Working on a fix.

@ihudedi
Copy link
Author

ihudedi commented Dec 11, 2024

Hi @Ndiritu
I saw you fix in the file but there is another call to reset in this file and we throw exception.
Could you please look at this ?
Thanks,
Itay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug A broken experience
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants