New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.net.SocketException: socket is closed #8400
Comments
Also posted in #7794 (comment) |
If you can reproduce it against a private server, then you could post code for a repro, and privately message the actual host so we can investigate. Without that, this isn't actionable, and not clear it's not a problem with your client or server. |
I am looking at the problem right now, definitely reproducible, will create GitHub separate repo to show the call, my postman call to the same server do not have the error |
have created a github repo and reproduced the error, https://github.com/jessicakfl/purplerain Installing profile for com.idigue.purplerain the error not happen every time, the first time succeeded, log here, 2024-05-08 16:19:25.414 19204-19204 System.out com.idigue.purplerain I kotlin.Unit seems like a threading issue, |
the treading error when write called at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109), other than print out more debug log, please provide apis about the intercepter setup to bypass the error |
i'am using implementation("com.squareup.okhttp3:okhttp-android:5.0.0-alpha.11"), okio.RealBufferedSource in the package seems wrong version, at okio.RealBufferedSource.indexOf(RealBufferedSource.kt:427) can't find at all |
Thanks for the repro, I'll dig in on the weekend. I really appreciate the effort to make it |
I realized ok is complicated and have extensive test coverage, would help with better documentation, might still not easy to reproduce on your end, will find out.. |
think I found the problems when looking at ok trace, still have questions though, 1, in implementation("com.squareup.okhttp3:okhttp-android:5.0.0-alpha.11"),okio.RealBufferedSource has wrong version in the package |
That's great. It sounds like OkHttp is doing the right thing, but sounds like you expect OkHttp to handle servers that don't return a response and just close the socket. Some feedback on the repro, you might want to consider higher level libraries that build on OkHttp like retrofit or Ktor. they should simplify some of your code compared to the OkHttp callbacks. |
it is write request, server throw no error, postman calls success though, watch dog from time to time timeout the same socket call not very stable product, wonder if you had a look at my repo, hope it's correct recommended ok api callbacks |
this problem occur randomly in a POST method, which could be called periodically.I suspect during async call in okhttp, part of the request send after connection closed, so increasing write time out didn't help, I don't have ok environment to test out, but it is bug need to investigate and fix, call trace paste for you, I can provide my call to your api if needed,
request failed -> java.net.SocketTimeoutException: timeout
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okio.SocketAsyncTimeout.newTimeoutException(JvmOkio.kt:147)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okio.AsyncTimeout.access$newTimeoutException(AsyncTimeout.kt:158)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:337)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okio.RealBufferedSource.indexOf(RealBufferedSource.kt:427)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.kt:320)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.http1.HeadersReader.readLine(HeadersReader.kt:29)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:179)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:111)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:95)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:84)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:65)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:205)
2024-05-08 08:45:47.646 16662-16705 System.out com.idigue.seashell I at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:537)
2024-05-08 08:45:47.647 16662-16705 System.out com.idigue.seashell I at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2024-05-08 08:45:47.647 16662-16705 System.out com.idigue.seashell I at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2024-05-08 08:45:47.647 16662-16705 System.out com.idigue.seashell I at java.lang.Thread.run(Thread.java:920)
2024-05-08 08:45:47.647 16662-16705 System.out com.idigue.seashell I Caused by: java.net.SocketException: Socket closed
2024-05-08 08:45:47.647 16662-16705 System.out com.idigue.seashell I at java.net.SocketInputStream.read(SocketInputStream.java:209)
2024-05-08 08:45:47.647 16662-16705 System.out com.idigue.seashell I at java.net.SocketInputStream.read(SocketInputStream.java:144)
2024-05-08 08:45:47.647 16662-16705 System.out com.idigue.seashell I at okio.InputStreamSource.read(JvmOkio.kt:94)
2024-05-08 08:45:47.647 16662-16705 System.out com.idigue.seashell I at okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:125)
The text was updated successfully, but these errors were encountered: