Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Android, DevServerHelper from calling okhttp3 response.body.string() twice #19088

Closed

Conversation

Jekiwijaya
Copy link
Contributor

@Jekiwijaya Jekiwijaya commented May 1, 2018

Fixing from call response.body.string() twice in DevServerHelper.java.
square/okhttp#1240 (comment)

I'm getting error like this

05-01 21:16:47.080 22836-23064/com.my.company.bundle E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
                                                                               Process: com.my.company.bundle, PID: 22836
                                                                               java.lang.IllegalStateException: closed
                                                                                   at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:398)
                                                                                   at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:392)
                                                                                   at okhttp3.internal.c.a(Util.java:449)
                                                                                   at okhttp3.v.string(ResponseBody.java:174)
                                                                                   at com.facebook.react.devsupport.f$8.onResponse(DevServerHelper.java:487)
                                                                                   at com.newrelic.agent.android.instrumentation.okhttp3.CallbackExtension.onResponse(CallbackExtension.java:41)
                                                                                   at okhttp3.s$a.c(RealCall.java:153)
                                                                                   at okhttp3.internal.b.run(NamedRunnable.java:32)
                                                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                                                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                                                                                   at java.lang.Thread.run(Thread.java:764)

Test Plan

  • In my case, My device is using a Proxy, and tried to connect the packager. When it failed from connecting packager through websocket, It crash by this line of code.

Related PRs

Release Notes

[ANDROID] [BUGFIX] [DevServerHelper] - fixing from calling body.string() twice.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 1, 2018
@Jekiwijaya Jekiwijaya changed the title Fix DevServerHelper from calling responser.body.string() twice Fix Android, DevServerHelper from calling responser.body.string() twice May 1, 2018
@react-native-bot react-native-bot added the Platform: Android Android applications. label May 1, 2018
@Jekiwijaya Jekiwijaya changed the title Fix Android, DevServerHelper from calling responser.body.string() twice Fix Android, DevServerHelper from calling response.body.string() twice May 1, 2018
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@Jekiwijaya Jekiwijaya changed the title Fix Android, DevServerHelper from calling response.body.string() twice Fix Android, DevServerHelper from calling okhttp3 response.body.string() twice May 1, 2018
@react-native-bot react-native-bot added the 🌐Networking Related to a networking API. label May 1, 2018
@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label May 2, 2018
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdvacca is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@Diaren
Copy link

Diaren commented May 25, 2018

This bug is/was also triggered when running react-native run-android and there is some other HTTP server instead of the packager running on port 8081 that returns a 200 OK response to /status or /message e.g.
printf 'HTTP/1.1 200 OK\r\nContent-Length: 5\r\nContent-Type: text/plain\r\n\r\nHello' | nc -l 8081

macdoum1 pushed a commit to macdoum1/react-native that referenced this pull request Jun 28, 2018
…g() twice

Summary:
Fixing from call response.body.string() twice in DevServerHelper.java.
square/okhttp#1240 (comment)

I'm getting error like this
```
05-01 21:16:47.080 22836-23064/com.my.company.bundle E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
                                                                               Process: com.my.company.bundle, PID: 22836
                                                                               java.lang.IllegalStateException: closed
                                                                                   at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:398)
                                                                                   at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:392)
                                                                                   at okhttp3.internal.c.a(Util.java:449)
                                                                                   at okhttp3.v.string(ResponseBody.java:174)
                                                                                   at com.facebook.react.devsupport.f$8.onResponse(DevServerHelper.java:487)
                                                                                   at com.newrelic.agent.android.instrumentation.okhttp3.CallbackExtension.onResponse(CallbackExtension.java:41)
                                                                                   at okhttp3.s$a.c(RealCall.java:153)
                                                                                   at okhttp3.internal.b.run(NamedRunnable.java:32)
                                                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                                                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                                                                                   at java.lang.Thread.run(Thread.java:764)
```

<!--
  Required: Write your motivation here.
  If this PR fixes an issue, type "Fixes #issueNumber" to automatically close the issue when the PR is merged.
-->

- In my case, My device is using a Proxy, and tried to connect the packager. When it failed from connecting packager through websocket, It crash by this line of code.
<!--
  Required: Write your test plan here. If you changed any code, please provide us with
  clear instructions on how you verified your changes work. Bonus points for screenshots and videos!
-->

<!--
  Does this PR require a documentation change?
  Create a PR at https://github.com/facebook/react-native-website and add a link to it here.
-->

<!--
  Required.
  Help reviewers and the release process by writing your own release notes. See below for an example.
-->

[ANDROID] [BUGFIX] [DevServerHelper] - fixing from calling body.string() twice.

<!--
  **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

    CATEGORY
  [----------]      TYPE
  [ CLI      ] [-------------]    LOCATION
  [ DOCS     ] [ BREAKING    ] [-------------]
  [ GENERAL  ] [ BUGFIX      ] [ {Component} ]
  [ INTERNAL ] [ ENHANCEMENT ] [ {Filename}  ]
  [ IOS      ] [ FEATURE     ] [ {Directory} ]   |-----------|
  [ ANDROID  ] [ MINOR       ] [ {Framework} ] - | {Message} |
  [----------] [-------------] [-------------]   |-----------|

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
Closes facebook#19088

Differential Revision: D7853822

Pulled By: mdvacca

fbshipit-source-id: c11a73ce2fa6d40b0a7bd8bc0fca7b07c6bc27ed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved. 🌐Networking Related to a networking API. Platform: Android Android applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants