简体   繁体   English

Android间歇性SSL套接字读取超时

[英]Android intermittent SSL Socket read timed out

I am building an android app that makes calls to an HTTP/REST api. 我正在构建一个可以调用HTTP / REST API的Android应用。 I have self signed a certificate for testing and added it to my phones trust store. 我已经自行签署了测试证书,并将其添加到我的电话信任存储中。

I have run into a very strange issue where I will receive the following exception: 我遇到了一个非常奇怪的问题,我将收到以下异常:

java.net.SocketTimeoutException: Read timed out
at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:705)
...

I am at a total loss as to how or why this is happening. 我对这种情况的发生方式或原因一无所知。 Important notes: 重要笔记:

  • This happens randomly, comes back after lots of request but sometimes goes away for a day or two. 这种情况是随机发生的,经过大量请求后会再次出现,但有时会消失一两天。
  • I cannot reliably reproduce the issue. 我无法可靠地重现该问题。
  • I have adjusted the timeout settings with no results. 我已经调整了超时设置,但没有结果。
  • The issue outlives the life-cycle of the application. 该问题超出了应用程序的生命周期。 Restarting the app has no effect, although it seems to resolve itself within 5 mins. 重新启动应用程序没有任何效果,尽管似乎可以在5分钟内解决。
  • If I am using a cookie store, removing it seems to resolve the issue temporally. 如果我使用cookie存储,将其删除似乎可以暂时解决该问题。 If I am not using a cookie store, a new instance of the HttpClient needs to be created (as cookies persist temporally with the instance of the HttpClient) 如果我不使用cookie存储,则需要创建HttpClient的新实例(因为cookie在HttpClient实例中会暂时保留)
  • It is not a DNS issue as I can resolve the endpoint (as I have another app that uses the same endpoint and the same crt). 这不是DNS问题,因为我可以解析端点(因为我有另一个使用相同端点和相同crt的应用程序)。
  • I am using the AsyncHttp library for android, but the issue still happens outside of using that library. 我正在为Android使用AsyncHttp库,但是在使用该库之外仍然会发生问题。
  • I have tried another device with another version of android (no luck). 我尝试了另一版本的android设备(没有运气)。

Interesting things I have tried: 我尝试过的有趣的事情:

  • I created a new AsyncHttp instance, made a request (without setting the cookiestore) and successfully received a response. 我创建了一个新的AsyncHttp实例,发出了一个请求(未设置cookiestore)并成功收到了响应。 Then the app creates another AsyncHttp instance with the cookie store and the issue persists. 然后,应用程序使用cookie存储创建另一个AsyncHttp实例,问题仍然存在。 Even outside the app life-cycle, the first (non cookied) request will work, but the second will not. 即使在应用程序生命周期之外,第一个(非cookie)请求也可以使用,但第二个则不能。
  • I tired turning off tcp_timestamp (temporally via the file in proc). 我厌倦了关闭tcp_timestamp(暂时通过proc中的文件)。 No change. 没变。

If anyone has some idea or experience with a similar issue, please let me know. 如果有人对类似问题有任何想法或经验,请告诉我。

这实际上是我的服务器代码中与会话相关的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM