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

Make DevTools configurable #17617

Closed
wants to merge 4 commits into from

Conversation

vovkasm
Copy link
Contributor

@vovkasm vovkasm commented Jan 15, 2018

Motivation

The main motivator for this change is #10027 ("__nw_connection_get_connected_socket_block_invoke Connection has no connected handler" error on iOS 10)
This issue about spam in log output makes application very hard to debug. Error logs generated from inside Apple frameworks when websocket connection can't be established and do not do any harm themselves, but they are repeated every 2 seconds by reconnects to React DevTools and this leads to many meaningless lines in console. This makes quick analysis of logs impossible without running DevTools.
Commit 878b7e4 tries to fix this by hacking system logging functions and filtering some messages. It works sometimes, but has drawbacks:

  1. It introduces stubbing of system API functions which is hard to debug and understand.
  2. It can hide really useful logs, we do not really know when and why similar errors can be logged from Apple frameworks
  3. It needs maintenance with each release of iOS because such errors can change - they are not a public API
  4. It is already not working on real devices ("__nw_connection_get_connected_socket_block_invoke Connection has no connected handler" in logs #10027 (comment)), because errors are different,
    more here "__nw_connection_get_connected_socket_block_invoke Connection has no connected handler" in logs #10027 (comment)

All this can be workarounded. I can simply run React DevTools utility and these logs disappear because now websocket connection is successful, but:

  1. Connection from real device to React DevTools is much harder and doesn't work "out of the box"
  2. I want to test my application in offline mode, want to switch networks, etc...

So as in #10027 (comment)
I implemented an option to disable DevTools connection from dev menu. Now developer can press Cmd+D and select Disable DevTools in menu to stop application's infinite attempts to reconnect to DevTools.

There are other variants to deal with this:

  1. Do not run DevTools automatically from InitializeCore.js, developers who need it can insert code like below in their application themselves:
require('react-devtools-core').connectToDevTools({
     host: '192.168.2.115',
     port: '8097',
});
  1. Allow to enable/disable DevTools by another mechanism which I am not aware of. I'd prefer not to pollute globals with magic flags but InitializeCore.js is called too early in application start, I simply can't (or don't see how) pass config to JS with other mechanisms.

Test Plan

  1. Make sure react-devtools are not running
  2. Open RNTester/RNTester.xcodeproj
  3. Run application
  4. See periodic spam in console like:
2018-01-16 00:39:40.801162+0300 RNTester[76181:13118879] [] nw_connection_get_connected_socket 11 Connection has no connected handler
2018-01-16 00:39:40.801606+0300 RNTester[76181:13118879] TCP Conn 0x60400016ff00 Failed : error 0:61 [61]
2018-01-16 00:39:42.819030+0300 RNTester[76181:13118882] [] nw_connection_get_connected_socket 12 Connection has no connected handler
2018-01-16 00:39:42.819472+0300 RNTester[76181:13118882] TCP Conn 0x60400016fa80 Failed : error 0:61 [61]
  1. Open dev menu (press Cmd+D)
  2. Press Disable DevTools
  3. After app reloading there is no more spam in console.

This setting persists like other dev menu settings and can be enabled/disabled. By default DevTools are enabled to not break current behavior.

Release Notes

[IOS] [ENHANCEMENT] [developer menu] - Automatic connection to React DevTools can be enabled/disabled from In-App Developer Menu

This setting will be used to disable react-devtools connection. By default it is enabled.
Add JS global variable __RCTDevToolsEnabled, and set it before main script execution.
Check this variable in InitializeCore.js and setup DevTools only if enabled.
Was added in 878b7e4 (fishhook nwlog_legacy_v to avoid log spam on websocket reconnect)
It is not needed anymore because we can disable DevTools (the only thing that try to infinity reconnects from device or simulator)
@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!

@pull-bot
Copy link

Warnings
⚠️

❗ Big PR - This PR is extremely unlikely to get reviewed because it touches 664 lines.

@facebook-github-bot large-pr

Attention: @shergin, @mhorowitz

Generated by 🚫 dangerJS

@vovkasm
Copy link
Contributor Author

vovkasm commented Jan 15, 2018

This PR is actually not big! It simply removes fishhook which is not used anymore.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. cla signed labels Jan 15, 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!

@vovkasm
Copy link
Contributor Author

vovkasm commented Jan 15, 2018

@emilsjolander Now I have some code to continue discussion at #10027 (comment)
Does this looks as acceptable workaround for you?

@facebook-github-bot
Copy link
Contributor

@vovkasm I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@vovkasm
Copy link
Contributor Author

vovkasm commented Feb 15, 2018

Actually we at work support our own fork for RN and can rebase and/or improve this concrete change at any time (within 1-2 days). But I want to be sure that this work not be lost... So I will do anything only if requested from human, not a bot ;-)
PS: Our fork is open. Current branches:
RN 0.53: https://github.com/vovkasm/react-native/tree/v0.53.0-woof.0
RN 0.52: https://github.com/vovkasm/react-native/tree/v0.52.1-woof.0

@sdwilsh sdwilsh removed the cla signed label Mar 1, 2018
@react-native-bot react-native-bot added Feature Request 🌟 Platform: iOS iOS applications. Ran Commands One of our bots successfully processed a command. labels Mar 16, 2018
@hramos hramos added Type: Enhancement A new feature or enhancement of an existing feature. and removed 🌟Feature Request labels Mar 19, 2018
@mmmulani
Copy link
Contributor

mmmulani commented May 9, 2018

DevTools are a pretty useful feature though and it's reasonable to think that most people will have them enabled always.

if we fix the logspew, what benefit does this provide?

@vovkasm
Copy link
Contributor Author

vovkasm commented May 10, 2018

If logspew fixed, only benefit of disabling DevTools is that one can debug application network depended behaviors (battery, sleep, etc...) in dev mode.

@cpojer
Copy link
Contributor

cpojer commented Jan 28, 2019

I don't think we'll want to support this change. It's rather complex and the majority of people won't really benefit from it. I'd much rather work on reducing the log spew than adding all this complexity to React Native.

@cpojer cpojer closed this Jan 28, 2019
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. Platform: iOS iOS applications. Ran Commands One of our bots successfully processed a command. Type: Enhancement A new feature or enhancement of an existing feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants