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.

ProtocolException: unexpected end of stream

See original GitHub issue

Not 100% reproduce depend on device (100% failed on vivo X20A version: 8.1.0).

Repro code

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        Timber.plant(Timber.DebugTree())
        net.setOnClickListener {
            Thread {
                Timber.w("network")
                val request = Request.Builder()
                        .url("http://45.63.13.41:3000/playlist/detail?id=2451836751")
                        .get()
                        .addHeader("Cache-Control", "no-cache")
                        .addHeader("Accept-Encoding", "gzip, deflate")
                        .build()

                val client = OkHttpClient()
                val response = client.newCall(request).execute()
                val body = response.body?.string()

                Timber.w("response = " + body)
            }.start()
        }
    }
}

Okhttp version: com.squareup.okhttp3:okhttp:4.1.0

StackTrace

E/AndroidRuntime: FATAL EXCEPTION: Thread-2
    Process: me.gengjiawen.quickstart, PID: 4865
    java.net.ProtocolException: unexpected end of stream
        at okhttp3.internal.http1.Http1ExchangeCodec$FixedLengthSource.read(Http1ExchangeCodec.kt:392)
        at okhttp3.internal.connection.Exchange$ResponseBodySource.read(Exchange.kt:279)
        at okio.Buffer.writeAll(Buffer.kt:1104)
        at okio.RealBufferedSource.readString(RealBufferedSource.kt:194)
        at okhttp3.ResponseBody.string(ResponseBody.kt:187)
        at me.gengjiawen.switchdemo.MainActivity$onCreate$1$1.run(MainActivity.kt:29)
        at java.lang.Thread.run(Thread.java:764)

Tried https://github.com/square/okhttp/issues/1490#issuecomment-78621872, but no luck.

Same code works on kotlin jvm. The url also works on curl, browser, Node.js.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
LebonNiccommented, Oct 1, 2019

I have contacted the support of my PaaS provider and they told me that this could be related to their reverse proxy. They have deployed a fix on their infrastructure and the issue seems to be solved.

1reaction
gengjiawencommented, Oct 1, 2019

yes, I am using Node.js.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.net.ProtocolException: unexpected end of stream
That exception is thrown by FixedLengthInputStream when the expected number of bytes (usually set in the content-length header of the response) ...
Read more >
ProtocolException: Unexpected end of stream · Issue #7880
"Unexpected end of stream" normally means that the server response indicated it will provide a certain number of bytes (specified in the Content ......
Read more >
Java.Net.ProtocolException: 'unexpected end of ... - MSDN
i try to input my Xamarin form app value to Sql server table using Asp.net Api but not working with "Java.Net.ProtocolException: 'unexpected end...
Read more >
Multipart form file send writeFully fails with "java.net. ...
ProtocolException : unexpected end of stream". This issue was imported from GitHub issue: https://github.com/ktorio/ktor/issues/1829.
Read more >
java.net.ProtocolException: unexpected end of stream
ProtocolException : unexpected end of stream. androidandroid-volleyokhttp. I am facing a strange issue, and I am not able to debug it out.
Read more >

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