SocketTimeoutException - " timeout" "读取超时"

时间:2016-09-22 13:22:11

标签: exception timeout retrofit okhttp

我正在编写针对MockWebServer运行OkHttp / Retrofit请求的测试。除此之外我还有测试超时。在这里,我注意到,我的一些超时测试不会一直产生同样的异常

虽然抛出的异常始终为SocketTimeoutException,但异常消息在两种可能性之间存在差异。有时我会

  • "timeout",有时
  • "Read timed out"

似乎没有明确的模式(它是有时产生这些异常消息中的一个或另一个的完全相同的测试)。

我认为不同的星座/原因会导致不同的信息......有人可以向我解释这两种情况之间的区别吗?

以下是相应的堆栈跟踪:

"读取超时"

Caused by: java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
    at java.net.SocketInputStream.read(SocketInputStream.java:170)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at okio.Okio$2.read(Okio.java:140)
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:238)
    at okio.RealBufferedSource.read(RealBufferedSource.java:45)
    at okhttp3.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:381)
    at okio.RealBufferedSource.read(RealBufferedSource.java:45)
    at okio.ForwardingSource.read(ForwardingSource.java:35)
    at retrofit2.OkHttpCall$ExceptionCatchingRequestBody$1.read(OkHttpCall.java:279)
    at okio.RealBufferedSource$1.read(RealBufferedSource.java:386)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
    at java.io.InputStreamReader.read(InputStreamReader.java:184)
    at com.google.gson.stream.JsonReader.fillBuffer(JsonReader.java:1287)
    at com.google.gson.stream.JsonReader.nextQuotedValue(JsonReader.java:1016)
    at com.google.gson.stream.JsonReader.nextName(JsonReader.java:787)
    at com.google.gson.internal.bind.TypeAdapters$29.read(TypeAdapters.java:739)
    at com.google.gson.internal.bind.TypeAdapters$29.read(TypeAdapters.java:714)
    at com.google.gson.internal.bind.TypeAdapters$35$1.read(TypeAdapters.java:910)
    at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:37)
    at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:25)
    at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:117)
    at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211)
    at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:106)

"超时"

Caused by: java.net.SocketTimeoutException: timeout
    at okio.Okio$3.newTimeoutException(Okio.java:212)
    at okio.AsyncTimeout.exit(AsyncTimeout.java:288)
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:242)
    at okio.RealBufferedSource.read(RealBufferedSource.java:45)
    at okhttp3.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:381)
    at okio.RealBufferedSource.read(RealBufferedSource.java:45)
    at okio.ForwardingSource.read(ForwardingSource.java:35)
    at retrofit2.OkHttpCall$ExceptionCatchingRequestBody$1.read(OkHttpCall.java:279)
    at okio.RealBufferedSource$1.read(RealBufferedSource.java:386)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
    at java.io.InputStreamReader.read(InputStreamReader.java:184)
    at com.google.gson.stream.JsonReader.fillBuffer(JsonReader.java:1287)
    at com.google.gson.stream.JsonReader.nextQuotedValue(JsonReader.java:1016)
    at com.google.gson.stream.JsonReader.nextName(JsonReader.java:787)
    at com.google.gson.internal.bind.TypeAdapters$29.read(TypeAdapters.java:739)
    at com.google.gson.internal.bind.TypeAdapters$29.read(TypeAdapters.java:714)
    at com.google.gson.internal.bind.TypeAdapters$35$1.read(TypeAdapters.java:910)
    at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:37)
    at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:25)
    at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:117)
    at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211)
    at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:106)

0 个答案:

没有答案