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:
- When retrieving a resource with okhttp, the connection used for the retrieval gets stored in the client's connectionPool.
- When turning off the network (e.g. by disabling wifi and data) the idle connections in the connectionPool somehow get corrupted.
- 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.
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: