vksdk / vk-sdk-kotlin

Unofficial VK SDK, written in Kotlin: make bots, use the API
https://vksdk.github.io/vk-sdk-kotlin
MIT License
70 stars 16 forks source link

BotsLongPollApi::exceptionHandler::error = java.net.SocketTimeoutException: timeout #23

Closed ghost closed 4 years ago

ghost commented 4 years ago

Раз в сутки примерно вылезает это исключение, причём авторестарт стоит, но он не реагирует на это. Просто зависает

BotsLongPollApi::exceptionHandler::error = java.net.SocketTimeoutException: timeout
java.net.SocketTimeoutException: timeout
        at okhttp3.internal.http2.Http2Stream$StreamTimeout.newTimeoutException(Http2Stream.kt:677)
        at okhttp3.internal.http2.Http2Stream$StreamTimeout.exitAndThrowIfTimedOut(Http2Stream.kt:686)
        at okhttp3.internal.http2.Http2Stream.takeHeaders(Http2Stream.kt:143)
        at okhttp3.internal.http2.Http2ExchangeCodec.readResponseHeaders(Http2ExchangeCodec.kt:96)
        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:100)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:82)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
        at com.petersamokhin.vksdk.http.VkOkHttpClient$applyConfig$$inlined$-addInterceptor$1.intercept(Interceptor.kt:90)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
        at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:197)
        at okhttp3.internal.connection.RealCall.execute(RealCall.kt:148)
        at com.petersamokhin.vksdk.http.VkOkHttpClient.executeSync(VkOkHttpClient.kt:138)
        at com.petersamokhin.vksdk.http.VkOkHttpClient.getSync(VkOkHttpClient.kt:87)
        at com.petersamokhin.vksdk.core.api.VkApi.getLongPollUpdates$core(VkApi.kt:125)
        at com.petersamokhin.vksdk.core.api.botslongpoll.VkBotsLongPollApi.getUpdatesResponse(VkBotsLongPollApi.kt:168)
        at com.petersamokhin.vksdk.core.api.botslongpoll.VkBotsLongPollApi.access$getUpdatesResponse(VkBotsLongPollApi.kt:26)
        at com.petersamokhin.vksdk.core.api.botslongpoll.VkBotsLongPollApi$startPolling$1.invokeSuspend(VkBotsLongPollApi.kt:108)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
petersamokhin commented 4 years ago

@XjCyan1de а можно на код посмотреть?

ghost commented 4 years ago

https://gist.github.com/XjCyan1de/eafc66ff421cf9a1e56595c7f19d7f05

ghost commented 4 years ago

Ошибка происходит раз в сутки-две

petersamokhin commented 4 years ago

@XjCyan1de к сожалению, как раз эта часть кода и не нужна — я хотел глянуть на инициализацию VkClient, которой как раз там не видно. Я подозреваю, что скорее всего проблема в неустановленных таймаутах при инициализации HttpClient.

Но также по своему опыту могу добавить, что 503/504 и схожие ошибки апи ВК может возвращать довольно часто. Могу предложить еще попробовать добавить логгинг и увидеть точно, с каким http кодом и какой респонс приходит, и откуда конкретно — тогда станет яснее, просто ли проблема в том, что у лонгполла таймаут больше, чем у http-клиента, или же проблемы на стороне сервера ВК (что вполне вероятно тоже может быть).

ghost commented 4 years ago
val VK_CLIENT = VkApiClient(VK_ID.toInt(), VK_TOKEN, VkApiClient.Type.Community, VkSettings(VkOkHttpClient()))
petersamokhin commented 4 years ago

@XjCyan1de https://vksdk.github.io/vk-sdk-kotlin/http-clients/#abstract-http-client-configuration и https://vksdk.github.io/vk-sdk-kotlin/http-clients/#use

Советую установить read timeout и connect timeout. Если не поможет — сделать подробное логгирование (см. мой предыдущий комментарий). Если проблема окажется в сервере ВК, то следует попробовать обрабатывать ошибку самому, если без копания в коде библиотеки обработать не получится и бот все равно останавливается — тогда уже я буду разбираться.

ghost commented 4 years ago

Поставил в Http клиенте таймаут на Int.MAX_VALUE, проблем больше не было) Видимо сервер вк залагивает и превышает дефолтный таймаут 30 секунд

petersamokhin commented 4 years ago

@XjCyan1de 30 секунд должно быть достаточно, ну минуту можно поставить, Int.MAX_VALUE не стоит :) Если появятся еще проблемы — welcome.