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.

Segment pool should be thread local

See original GitHub issue

okio version: 1.4.0 okhttp version: 2.4.0

java.lang.NullPointerException: Attempt to write to field 'okio.Segment okio.Segment.prev' on a null object reference
    at okio.Segment.push(Segment.java:96)
    at okio.Buffer.writableSegment(Buffer.java:1120)
    at okio.Buffer.write(Buffer.java:940)
    at okio.Buffer$1.write(Buffer.java:74)
    at java.io.OutputStream.write(OutputStream.java:82)
    at retrofit.mime.JSONEncodedTypedOutput.writeTo(JSONEncodedTypedOutput.java:56)
    at retrofit.client.OkClient$1.writeTo(OkClient.java:88)
java.lang.ArrayIndexOutOfBoundsException: length=2048; index=2048
    at okio.Buffer.writeUtf8(Buffer.java:818)
    at com.squareup.okhttp.HttpUrl.percentDecode(HttpUrl.java:1366)
    at com.squareup.okhttp.HttpUrl.percentDecode(HttpUrl.java:1349)
    at com.squareup.okhttp.HttpUrl.percentDecode(HttpUrl.java:1355)
    at com.squareup.okhttp.HttpUrl.<init>(HttpUrl.java:308)
    at com.squareup.okhttp.HttpUrl.<init>(HttpUrl.java:255)
    at com.squareup.okhttp.HttpUrl$Builder.build(HttpUrl.java:833)
    at com.squareup.okhttp.HttpUrl$Builder.parse(HttpUrl.java:999)
    at com.squareup.okhttp.HttpUrl.parse(HttpUrl.java:585)
    at com.squareup.okhttp.Request$Builder.url(Request.java:156)
    at retrofit.client.OkClient.createRequest(OkClient.java:57)
    at retrofit.client.OkClient.execute(OkClient.java:53)

And sometimes the ArrayIndexOutOfBoundsException happens in writeInt, or reading the Response stream returned corrupted data.

These two exceptions happens a lot while in multi thread, I reviewed all the source code still do not know why…

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:21 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
swankjessecommented, Aug 8, 2019

That’s for Kotlin native only.

0reactions
15characterlimicommented, Aug 8, 2019

@bendb-instacart that suggests that a quick/hacky fix has been implemented, but note that that approach has downsides (specifically that each thread that makes a network connection holds on to 64 KBytes of memory for as long as the thread exists, see my comment above), which is probably why this issue here has not yet been marked as resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java Cached thread pool and thread local
Let say I have a ThreadLocal variable called 'a'. And I use a CachedThreadPool to obtain new threads. When a thread is reused,...
Read more >
java - Reasonable use of thread pools and thread variables
The thread pool is a "pooled" thread usage mode. By creating a certain number of threads, these threads are in a ready state...
Read more >
OSDev.org • View topic - Is thread local storage a good solution?
For thread pools this means that either you need to reinitialize the TLS for each run or use the same values from previous...
Read more >
Comparing the performance of using Thread-Local Object ...
Comparing the performance of using Thread-Local Object Pool under various ... seeking to optimize targeted campaigns, or general market segmentation.
Read more >
Java ExecutorService and Thread Pools Tutorial
Most of the executor implementations use thread pools to execute tasks. A thread pool is nothing but a bunch of worker threads that...
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