RealWebSocket send throws writerTask NPE
See original GitHub issueokhttp 4.3.0 throws NPE each time I try to send command via websocket.
writerTask
is null in RealWebSocket::runWriter
private fun runWriter() {
this.assertThreadHoldsLock()
taskQueue.schedule(writerTask!!) // crashes in this line
}
Stacktrace:
Caused by kotlin.KotlinNullPointerException
at okhttp3.internal.ws.RealWebSocket.runWriter + 398(RealWebSocket.java:398)
at okhttp3.internal.ws.RealWebSocket.send + 352(RealWebSocket.java:352)
at okhttp3.internal.ws.RealWebSocket.send + 332(RealWebSocket.java:332)
test:
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.WebSocketListener
import okhttp3.mockwebserver.MockWebServer
import org.junit.Rule
import org.junit.Test
class OkHttpBug {
@get:Rule
val server = MockWebServer()
@Test
fun test() {
val request = Request.Builder()
.url(server.url("/path"))
.header("User-Agent", "Test Case")
.build()
val client = OkHttpClient()
val listener = object : WebSocketListener() {
}
val command = """{ "id": "file" }"""
val webSocket = client.newWebSocket(request, listener)
webSocket.send(command)
webSocket.close(1000, "RealWebSocket crashes with runWriter writerTask!! NPE")
}
}
This seems to be 100% reproducible in 4.3.0. Had about 1000 crashes on that version on small amount of sessions. This (almost) does not happen with the same code on okhttp 4.2.2 (2 crashes in 1000x user count in much longer period)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
FYI, OkHttp 4.3.1 is released.
Great bug report. Will try to get a release out tonight. https://github.com/square/okhttp/pull/5707