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

Getting a SocketTimeoutException when requesting video sessions using RawStatisticsApi #71

Open
slauriere opened this issue Dec 12, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@slauriere
Copy link

I'm getting the error below when requesting video sessions to the RawStatisticsApi.

Steps to reproduce

Run the program below, after replacing "APIKEY" and "VIDEOID" by a working API key and an existing video identifier.

import video.api.client.ApiVideoClient;
import video.api.client.api.ApiException;
import video.api.client.api.models.*;
import video.api.client.api.clients.RawStatisticsApi;
import java.util.*;

public class ApiVideoGetVideoCount
{
    public static void main(String[] args) {
        ApiVideoClient client = new ApiVideoClient("APIKEY");

        RawStatisticsApi apiInstance = client.rawStatistics();

        String videoId = "VIDEOID";
        String period = "2022-11-15";
        Map<String, String> metadata = new HashMap();
        Integer currentPage = 1;
        Integer pageSize = 25;

        try {
            Page<VideoSession> result = apiInstance.listVideoSessions(videoId, period)
                .metadata(metadata)
                .currentPage(currentPage)
                .pageSize(pageSize)
                .execute();
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling RawStatisticsApi#listVideoSessions");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getMessage());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Results

The request is executed successfully when using the current day as a period (eg "2022-12-12"). However when using a day in the past (eg "2022-11-15") or a period covering a month (eg "2022-11") or a year (eg "2022"), the error below with a SocketTimeoutException is raised. The video used in this bug report was uploaded in October 2022.

Exception when calling RawStatisticsApi#listVideoSessions
Status code: 0
Reason: java.net.SocketTimeoutException: timeout
Response headers: null
video.api.client.api.ApiException: java.net.SocketTimeoutException: timeout
	at video.api.client.api.ApiClient.execute(ApiClient.java:883)
	at video.api.client.api.clients.RawStatisticsApi.listVideoSessionsWithHttpInfo(RawStatisticsApi.java:784)
	at video.api.client.api.clients.RawStatisticsApi.access$1300(RawStatisticsApi.java:30)
	at video.api.client.api.clients.RawStatisticsApi$APIlistVideoSessionsRequest.execute(RawStatisticsApi.java:912)
	at ApiVideoGetVideoCount.main(ApiVideoGetVideoCount.java:29)
Caused by: java.net.SocketTimeoutException: timeout
	at okio.Okio$4.newTimeoutException(Okio.java:232)
	at okio.AsyncTimeout.exit(AsyncTimeout.java:286)
	at okio.AsyncTimeout$2.read(AsyncTimeout.java:241)
	at okio.RealBufferedSource.indexOf(RealBufferedSource.java:358)
	at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:230)
	at okhttp3.internal.http1.Http1ExchangeCodec.readHeaderLine(Http1ExchangeCodec.java:242)
	at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.java:213)
	at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.java:115)
	at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:94)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at video.api.client.api.ApiClient$2.intercept(ApiClient.java:1258)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:43)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at video.api.client.api.auth.ApiVideoAuthInterceptor.intercept(ApiVideoAuthInterceptor.java:35)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229)
	at okhttp3.RealCall.execute(RealCall.java:81)
	at video.api.client.api.ApiClient.execute(ApiClient.java:879)
	... 4 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:1454)
	at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:1065)
	at okio.Okio$2.read(Okio.java:140)
	at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
	... 31 more

Process finished with exit code 0

Environment

  • Java version: OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu222.04, mixed mode, sharing)
  • API client version: java-api-client 1.2.7

Additional context

  • Example of a public video identifier which raises the issue : vi3zHNNvOEkktkWGXdwJvK8Y
  • Any video in my workspace triggers the issue, both in the sandbox and the production environments
@slauriere slauriere added the bug Something isn't working label Dec 12, 2022
@olivier-lando
Copy link
Member

olivier-lando commented Dec 12, 2022

Hi @slauriere
The response time for this kind of requests can indeed be long. This is a known problem that we have planed to work on in the future. In the meantime, you can increase the client timeout like this:

client.getHttpClient().setReadTimeout(60000); // set the read timeout to 60sec (default is 10sec)

@slauriere
Copy link
Author

Thank you for your help, @olivierapivideo. I've increased the timeout to 60 sec indeed, querying the API for a period of one month for a video having only a few hits and I'm still getting a timeout exception. I've then increased the timeout to 120 sec and then got another type of error:

Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
	at com.google.gson.Gson.fromJson(Gson.java:1003)
	at com.google.gson.Gson.fromJson(Gson.java:956)
	at com.google.gson.Gson.fromJson(Gson.java:905)
	at video.api.client.api.ApiException.<init>(ApiException.java:53)
	at video.api.client.api.ApiException.<init>(ApiException.java:99)
	at video.api.client.api.ApiClient.handleResponse(ApiClient.java:980)
	at video.api.client.api.ApiClient.execute(ApiClient.java:880)
	at video.api.client.api.clients.RawStatisticsApi.listVideoSessionsWithHttpInfo(RawStatisticsApi.java:784)
	at video.api.client.api.clients.RawStatisticsApi.access$1300(RawStatisticsApi.java:30)
	at video.api.client.api.clients.RawStatisticsApi$APIlistVideoSessionsRequest.execute(RawStatisticsApi.java:912)
	at ApiVideoGetVideoCount.main(ApiVideoGetVideoCount.java:31)
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
	at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385)
	at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:183)
	at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:145)
	at com.google.gson.Gson.fromJson(Gson.java:991)
	... 10 more

@ThibaultBee
Copy link
Member

Hi @slauriere,

We just released a new endpoint for Analytics:

Calls to this new Analytics endpoint will be faster than calling RawAnalytics.

@slauriere
Copy link
Author

Hello @ThibaultBee, Many thanks for letting me know, we'll test this new version asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants