Android random exceptions on HTTP calls. Why?

2019-07-22 17:29发布

问题:

I'm testing my app on 3 devices so far. One device LG Optimus from Sprint never throws exceptions on https calls (maybe once in a week)

Nexus S on T-Mobile almost every hour come up with something like this:

Read error: ssl=0x3f4060: I/O error during system call, Connection reset by peer

Now I got tablet for testing (S7 slim) and it's connected via WiFi and I get errors like:

SSL shutdown failed: I/O error during system call, Broken pipe

Do you know why those happen and is there any way to avoid them?

回答1:

Rest by peer means the server is rejecting/losing your connection. The SSL failure is probably a direct result of the connection reset. My bet is that this happen when switching networks (wifi to 3G) in the middle of some long standing connection.

If possible create a connection, do any IO, and disconnect as quickly as possible. If you do need to handle long persistent connection be prepared to handle such exceptions and reconnect behind the scenes.



标签: android http