title: Android app crash okhttp3 HTTP FAILED: javax.net.ssl.SSLException: Read error: I/O error during system call, Software caused connection abort
body: <p>I am working on android native kotlin project.
  <br>I am testing app in android real <strong>Oneplus 6</strong> device with <strong>Android version 10</strong>.
  <br> Please find below details from build.gradle file for latest okhttp and retrofit dependencies which I am using for project.
  <br><strong>okhttp</strong></p>
  <pre><code>implementation &quot;com.squareup.okhttp3:okhttp:4.9.0&quot;
  implementation &quot;com.squareup.okhttp3:logging-interceptor:4.9.0&quot;` 
  </code></pre>
  <p><strong>Retrofit</strong></p>
  <pre><code>implementation 'com.squareup.retrofit2:retrofit:2.9.0'
  implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
  </code></pre>
  <p>I have already set relevant timeouts for okhttpclient.</p>
  <pre><code>.connectTimeout(HTTP_CONNECT_TIMEOUT, TimeUnit.SECONDS)
  .readTimeout(HTTP_READ_TIMEOUT, TimeUnit.SECONDS)
  .writeTimeout(HTTP_WRITE_TIMEOUT, TimeUnit.SECONDS)
  </code></pre>
  <p>I am using <strong>okhttp3.Interceptor</strong>. Please find implementation below.</p>
  <pre><code>import okhttp3.Interceptor
  import okhttp3.Request
  import okhttp3.Response
  
  class AuthorizationInterceptor(private val sharedPreferenceService: SharedPreferenceService) :
      Interceptor {
  
      override fun intercept(chain: Interceptor.Chain): Response {
          val requestBuilder = chain.request().newBuilder()
              .addHeader(&quot;Content-Type&quot;, &quot;application/json&quot;)
              .addHeader(&quot;Accept&quot;, &quot;application/json&quot;)
  
          return chain.proceed(requestBuilder.build())
      }
    }
  </code></pre>
  <p><strong>Observations / Issues</strong></p>
  <ol>
  <li>If API call is in progress and we try to change or disable network/internet, okhttp3 itself internally crashing as soon as below line executes from above snippets so App is crashing.
  <code>return chain.proceed(requestBuilder.build())</code></li>
  </ol>
  <p>I have figured out below <strong>okhttp internal crashes logs</strong> from my android studio that can help you to find root cause and fixes.</p>
  <pre><code>FATAL EXCEPTION: main
      Process: com.pg.posm, PID: 8770
      javax.net.ssl.SSLException: Read error: ssl=0x7afca87588: I/O error during system call, Software caused connection abort
  </code></pre>
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.pg.posm, PID: 26238
      java.net.ConnectException: Failed to connect to hostname/ip:port
  </code></pre>
  <p>I also tried to wrap above Interceptor snippets using try-catch but still okhttp3 itself crashing so App is crashing.
  <br>We don't have any control to solve it.
  <br>Please find below Interceptor snippets with wrapped try-catch implementation.</p>
  <pre><code>import okhttp3.Interceptor
  import okhttp3.Request
  import okhttp3.Response
  import timber.log.Timber
  import java.io.IOException
  
  class AuthorizationInterceptor(private val sharedPreferenceService: SharedPreferenceService) :
      Interceptor {
  
      @Throws(IOException::class)
      override fun intercept(chain: Interceptor.Chain): Response {
          val requestBuilder = chain.request().newBuilder()
              .addHeader(&quot;Content-Type&quot;, &quot;application/json&quot;)
              .addHeader(&quot;Accept&quot;, &quot;application/json&quot;)
       
          try {
              return chain.proceed(requestBuilder.build())
          }catch (e: Throwable) {
              
              if (e is IOException) {
                  
                  throw e
              } else {
                  
                  throw IOException(e)
              }
          }
      }   
  }
  </code></pre>
  <p>Anyone can try to make small android project with relevant setup and snippets and see.
  <br>Please provide necessary fixes or approach for this blocker issue as many people are facing in the world.
  <br>Please let me know in case you need more details. I would more than happy to provide you.</p>