question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fetch has weird behavior for 0.45.1 when debugger is attached

See original GitHub issue

Description

I’ve upgraded one of our apps to 0.45.1 (from 0.42.3) and fetch has some weird behaviour when attaching the Chrome debugger. The Promise with the Response returns as normally. What is weird is if I try to return any of the Promises from the Response, e.g. response.text(), then I must touch/click the UI in order for it to continue.

For example, this works fine:

fetch('https://github.com/facebook/react-native')
  .then((res) => console.log(res));

It will log the Response-object when the GET completes. But if I add another then to return for example the text of the response:

fetch('https://github.com/facebook/react-native')
  .then((res) => res.text())
  .then((text) => {
    console.log(text)
  });

Then I must touch/click the UI in order for it to run the last then.

If I set a break point into the function which handles the console.log, I even see from the call-stack that it is callFunctionReturnFlushedQueue with the touch-event as scope variables which triggers the Promise resolution: image

Reproduction Steps

  1. Download the below sample project. Important file is Core.js.
  2. Run the app. Note that the UI quickly goes from “Not done” -> “Done 😄”
  3. Attach debugger, reload app. Note that it stays on “Not done”.
  4. Click the UI, it should go to “Done 😄”.

Sample Code

Sample project here.

Additional Information

  • React Native version: 0.45.1
  • Platform: Both
  • Development Operating System: macOS
  • Build tools: Both iOS/Android.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:13
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
cbrevikcommented, Jul 11, 2017

So, I have a bit stronger suspicion that it is “sleep” related.

If you debug the app in Xcode, and set a break point in createTimer (used by setTimeout, setInterval, etc) using RN 0.45.1, if you do do not have the debugger attached, then it will break into that method and create a new timer every two seconds.

While if you have the Chrome debugger attached, it will only break into it a couple of times and then stop.

Testing the same code with RN 0.44.3, it always break into the method every two seconds, regardless if the debugger is attached or not.

Turns out createTimer is in this case called from setTimeout, which has the following stack trace:

image

Drilling into the arguments at the bottom of the stack I find: image

websocketFailed in turn seems to be related to RCTWebSocket connection failing. Which is called here. If you set a break point into that method you see the same behaviour. It will break into it every two seconds, except for RN 0.45.1 with Chrome debugger attached.

Wondering if it might be related to #10027, and any fixes done there? That issue thread is a bit sparse on info though.

Or, I might be completely wrong here. It makes no sense that some random timer polling WebSocket-connections should keep the rest alive when debugging. But that’s as far as I’ve gotten thus far.

1reaction
cbrevikcommented, Jul 11, 2017

@mikelambert I read that comment but it seemed (at first glance) like the fix was Android-specific?

@javache Thanks! Did a simple test with 0.47.0-rc.1, seems like that commit fixed it. Closing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xcode 11 hangs while attaching debugger to ios process
I have tried the "unpair phone" option in devices in xcode but it does nothing. I don't see anything in settings related to...
Read more >
Program only crashes as release build -- how to debug?
The Debug and RelWithDebInfo configurations worked well for my project, but not the Release one. The reason behind this behavior is probably ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found