Skip to content

Idle connection breaks when turning data off and on. #4079

@roberthoenig

Description

@roberthoenig

I first thought this to be an issue with React Native and filed an issue there: facebook/react-native#19709

However, further debugging makes me believe that the issue might lie within okhttp.

I created a tiny Github repo that reproduces this bug with okhttp in an Android app:

https://github.com/roberthoenig/react-native-fetch-bug

(Don't get confused by the repo name react-native-fetch-bug: The example doesn't use React Native at all, it's just where I encountered this bug first.)

The repo's README.md also contains steps to reproduce the issue.

Here is my theory of what's going on:

  1. When retrieving a resource with okhttp, the connection used for the retrieval gets stored in the client's connectionPool.
  2. When turning off the network (e.g. by disabling wifi and data) the idle connections in the connectionPool somehow get corrupted.
  3. After turning the network back on and making a new request to the same resource, okhttp will try to reuse the existing idle connection in the connectionPool. That connection is corrupted, however, and will silently fail. The symptom is that no request gets dispatched, and no errors are thrown. After a couple minutes, however, things seem to recover and the request gets dispatched as if nothing happened.

Metadata

Metadata

Assignees

No one assigned

    Labels

    androidRelates to usage specifically on AndroidbugBug in existing codeneeds infoMore information needed from reporter

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions