question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RealWebSocket send throws writerTask NPE

See original GitHub issue

okhttp 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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
swankjessecommented, Jan 7, 2020

FYI, OkHttp 4.3.1 is released.

1reaction
swankjessecommented, Jan 7, 2020

Great bug report. Will try to get a release out tonight. https://github.com/square/okhttp/pull/5707

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found