msgraph-sdk-java icon indicating copy to clipboard operation
msgraph-sdk-java copied to clipboard

Socket Timeout while fetching all file details in DL using NextLink

Open nikhil452 opened this issue 3 years ago • 2 comments

Getting Socket Timeout after try to fetch file details using ListItemCollectionRequest. after executing ListItemCollectionRequest.get() response take much time because of which socket timeout is occured.

Stack trace : com.microsoft.graph.core.ClientException: Error executing the request at com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(CoreHttpProvider.java:410) at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:225) at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:202) at com.microsoft.graph.http.BaseCollectionRequest.send(BaseCollectionRequest.java:103) at com.microsoft.graph.http.BaseEntityCollectionRequest.get(BaseEntityCollectionRequest.java:78) Caused by: java.net.SocketTimeoutException: timeout at okio.SocketAsyncTimeout.newTimeoutException(JvmOkio.kt:147) at okio.AsyncTimeout.access$newTimeoutException(AsyncTimeout.kt:158) at okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:337) at okio.RealBufferedSource.indexOf(RealBufferedSource.kt:427) at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.kt:320) at okhttp3.internal.http1.HeadersReader.readLine(HeadersReader.kt:29) at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:178) at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:106) at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:79) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at com.microsoft.graph.httpcore.RedirectHandler.intercept(RedirectHandler.java:137) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at com.microsoft.graph.httpcore.RetryHandler.intercept(RetryHandler.java:177) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at com.microsoft.graph.httpcore.AuthenticationHandler.intercept(AuthenticationHandler.java:59) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at com.microsoft.graph.httpcore.TelemetryHandler.intercept(TelemetryHandler.java:69) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201) at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154) at com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(CoreHttpProvider.java:407) ... 16 more Caused by: java.net.SocketTimeoutException: Read timed out at java.base/java.net.SocketInputStream.socketRead0(Native Method) at java.base/java.net.SocketInputStream.socketRead(SocketInputStream.java:115) at java.base/java.net.SocketInputStream.read(SocketInputStream.java:168) at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140) at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:478) at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:472) at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:70) at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1364) at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:973) at okio.InputStreamSource.read(JvmOkio.kt:94) at okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:125)

Expected behavior

ListItemCollectionRequest.get() should give file details of next page and this continues until no file changes in DL exist.

Actual behavior

Getting Socket Timeout after running ListItemCollectionRequest.get(). The request taking more than socket timeout time. This issue is intermittent. We observe this issue when more than 5000 files are added to DL.

Steps to reproduce the behavior

  1. Create DL on SharePoint.
  2. Add some files to dl.
  3. Execute ListItemCollectionRequest.get() and continue until every page changes is fetched.

nikhil452 avatar Sep 14 '22 10:09 nikhil452

just want to mention that this behaviour is not limited to Sharepoint. Its also happening the same way with calendar events using microsoft-graph so I guess it's a bigger problem. Some internet research mention so problems with http/2 vs http/1.1 protocol starting from java version 9

ghost avatar Oct 06 '22 00:10 ghost

@nikhil452

I'm playing around a bit with

final OkHttpClient graphHttpClient =
    HttpClients.createDefault(tokenCredentialAuthProvider)
            .newBuilder()
            .protocols(Arrays.asList(Protocol.HTTP_1_1))
            .connectTimeout(Duration.ofSeconds(60))
            .readTimeout(Duration.ofSeconds(60))
            .build();

 final GraphServiceClient graphClient =
    GraphServiceClient
            .builder()
            .httpClient(graphHttpClient)
            .buildClient();

and it works for me at least for calendar events maybe it can help you (even though I know that extending the timeouts shouldn't and couldn't be a fix)

ghost avatar Oct 06 '22 01:10 ghost

Hi @nikhil452 , would you mind sharing some information regarding which version of the sdk you are using as well as a sample code snippet. I believe that what @CSJaSveWei has could serve as a workaround, though as they acknowledged, it isn't best practice to extend the connection timeout as it could raise a security issue. Unfortunately, at the moment we don't have a page iterator which sounds like it would help solve this issue, we are currently working to include this in our next version of our SDK. In the meantime, I would suggest using the asynchronous method such as getAsync(). Let me know if the problem persists.

ramsessanchez avatar Feb 02 '23 15:02 ramsessanchez

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

ghost avatar Feb 06 '23 16:02 ghost