0

我有一个移动应用程序,它对我们的 REST API 进行大约 15 次 API 调用。其中大部分是 GET、POST、PUT 并包含中小型 JSON 正文/响应。我们正在使用 OKHTTP3 3.8.1 。

我们对 API Gateway->Lambda 进行了一次调用,其中包含稍大的 JSON 主体(小于 500kb)。

向 API Gateway 发出的一个调用相当一致地失败。但是,只有在我们在 Amazon Kindle Fire 7 上进行测试时它才会失败。该呼叫适用于 Kindle Fire 8 以及我们测试过的所有其他 Android 手机/平板电脑。

我创建了另一个应用程序来使用复制粘贴的代码来测试这个调用。在测试应用程序中,调用不会失败。但是,该应用程序没有拨打我们的其他电话,也没有使用 BLE 或任何其他资源。

当调用失败时,服务器(API 网关)根本不会收到请求(Nothing is Logged)。所以我认为问题在于从平板电脑上获取数据。

这是我们在失败时得到的堆栈跟踪。

java.net.SocketTimeoutException
 at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
 at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)
 at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
 at okio.Okio$2.read(Okio.java:139)
 at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
 at okio.RealBufferedSource.indexOf(RealBufferedSource.java:345)
 at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:217)
 at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:211)
 at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
 at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:75)
 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
 at com.company.app.helpers.http.HTTPHelpers$LoggingInterceptor.intercept(HTTPHelpers.java:202)
 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
 at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
 at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
 at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
 at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
 at com.company.app.helpers.http.HTTPHelpers$HeaderInterceptor.intercept(HTTPHelpers.java:225)
 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
 at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
 at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
 at okhttp3.RealCall$AsyncCall.execute(RealCall.java:135)
 at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
 at java.lang.Thread.run(Thread.java:818)

如果有人对我们为什么会收到此错误以及可能的解决方法有任何想法,我将不胜感激任何建议!

编辑 - 我们已尝试增加超时,但呼叫仍然没有离开平板电脑。我们已经确认通话不会使用代理离开平板电脑。

此外,该问题似乎与同时使用 BLE 和 HTTP 有关。

4

1 回答 1

0

尝试在 okhttp 中增加超时时间

new OkHttpClient.Builder() .connectTimeout(90, TimeUnit.SECONDS).readTimeout(90, TimeUnit.SECONDS) .writeTimeout(90, TimeUnit.SECONDS).build();
于 2017-09-06T16:06:09.027 回答