Skip to content

Conversation

@henter
Copy link
Contributor

@henter henter commented May 10, 2015

Just trying to getCurrentPosition , and found the errorBlock of location request in timeout handler would cause red error like this:

2015-05-10 17:50:39.607 [warn][tid:com.facebook.React.JavaScript] "Warning: Cannot find callback with CBID 5. Native module may have invoked both the success callback and the error callback."
2015-05-10 17:50:39.610 [error][tid:com.facebook.React.JavaScript] "Error: null is not an object (evaluating 'cb.apply')
 stack: 
  _invokeCallback  index.ios.bundle:7593
  <unknown>        index.ios.bundle:7656
  <unknown>        index.ios.bundle:7648
  perform          index.ios.bundle:6157
  batchedUpdates   index.ios.bundle:13786
  batchedUpdates   index.ios.bundle:4689
  <unknown>        index.ios.bundle:7647
  applyWithGuard   index.ios.bundle:882
  guardReturn      index.ios.bundle:7421
  processBatch     index.ios.bundle:7646
 URL: http://192.168.100.182:8081/index.ios.bundle
 line: 7593
 message: null is not an object (evaluating 'cb.apply')"

img_0837

I'm not sure if there is a better way to avoid multiple callback which caused the error,
but I don't think that the errorBlock should be called in timeout handler.
So, just remove it.

update: to invalidate the timer after success or error callback.

I just use the demo code of Geolocation

@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 10, 2015
@ide
Copy link
Contributor

ide commented May 11, 2015

This leaks memory on the JS side if the request times out and will also cause the JS app to hang forever if the callback isn't invoked. Better to cancel the timer if the location request invokes either its success or error callback.

@henter
Copy link
Contributor Author

henter commented May 11, 2015

@ide yeah, that's a great idea.
code updated. :-)

@henter henter changed the title [GeoLocation] remove errorBlock in timeout handler [GeoLocation] invalidate timer after success or error callback May 11, 2015
@ide
Copy link
Contributor

ide commented May 15, 2015

@henter this looks good but can you please verify that the NSTimer is scheduled and invalidated on the same run loop (check with https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFRunLoopRef/index.html#//apple_ref/c/func/CFRunLoopGetCurrent)?

Apple says:

you should always call the invalidate method from the same thread on which the timer was installed

In -[RCTLocationRequest dealloc] you should check _timeoutTimer.valid since I believe it will crash the app if a timer is invalidated twice.

Also please squash your commits (git rebase -i) into one commit so that it's easier to review and bisect.

Otherwise, this PR looks good to me.

@henter
Copy link
Contributor Author

henter commented May 15, 2015

@ide thanks. code updated. :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

@ide
Copy link
Contributor

ide commented May 15, 2015

Left one small comment if you want to update it but will mark this as accepted.

@henter
Copy link
Contributor Author

henter commented May 15, 2015

updated.

@ide
Copy link
Contributor

ide commented May 15, 2015

@vjeux if I say:
@facebook-github-bot import
will it work? ;)

@vjeux
Copy link
Contributor

vjeux commented May 15, 2015

You need it in its own line. It actually may work with you since you have a fb employee vc

@ide
Copy link
Contributor

ide commented May 15, 2015

@facebook-github-bot import

@reconbot
Copy link

Looking forward to see this land. 👍

reconbot added a commit to wizarddevelopment/farmers-market-app that referenced this pull request May 18, 2015
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: space after if and space after (

@henter
Copy link
Contributor Author

henter commented May 20, 2015

code updated. @ide @vjeux

@ide
Copy link
Contributor

ide commented May 20, 2015

Thanks @henter. This looks fine to me.

@vjeux
Copy link
Contributor

vjeux commented May 20, 2015

@facebook-github-bot import

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1402019833455864/int_phab to review.

Copy link
Contributor

Choose a reason for hiding this comment

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

The new invalidate calls shouldn't be necessary because this should be invalidating the timers because all the requests should be dealloc'd at this point. If that's not happening, there is probably a retain cycle or something? cc @nicklockwood

@sahrens
Copy link
Contributor

sahrens commented May 20, 2015

Did you have a repro case that failed 100% without this PR and 0% with it? I'm afraid there might be something else going wrong.

@vjeux vjeux assigned sahrens and unassigned ide May 20, 2015
@sahrens
Copy link
Contributor

sahrens commented May 22, 2015

ping @ide, @henter on my comment - am I missing something?

@ide
Copy link
Contributor

ide commented May 22, 2015

@sahrens My view on this is: covering up the retain cycle (if there is one) is bad and we should fix that. I do think the explicit -[invalidate] calls clarify the intent here, since we want to stop the timer whether or not the request is deallocated.

I haven't profiled the code for leaks but it looks like there is a cycle between request.timer and timer.userInfo (which is the request object). A nice thing about calling -[NSTimer invalidate] is that it clears the strong references to the timer's target and userInfo properties, which should break the cycle.

@sahrens
Copy link
Contributor

sahrens commented May 23, 2015

Cool, thanks - I'll bring this in.

On May 22, 2015, at 4:52 PM, James Ide [email protected] wrote:

@sahrens My view on this is: covering up the retain cycle (if there is one) is bad and we should fix that. I do think the explicit -[invalidate] calls clarify the intent here, since we want to stop the timer whether or not the request is deallocated.

I haven't profiled the code for leaks but it looks like there is a cycle between request.timer and timer.userInfo (which is the request object). A nice thing about calling -[NSTimer invalidate] is that it clears the strong references to the timer's target and userInfo properties, which should break the cycle.


Reply to this email directly or view it on GitHub.

tadeuzagallo pushed a commit to tadeuzagallo/react-native that referenced this pull request May 28, 2015
Summary:
Just trying to [getCurrentPosition](https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/Geolocation.js#L45) , and found the `errorBlock` of location request in timeout handler would cause red error like this:

```
2015-05-10 17:50:39.607 [warn][tid:com.facebook.React.JavaScript] "Warning: Cannot find callback with CBID 5. Native module may have invoked both the success callback and the error callback."
2015-05-10 17:50:39.610 [error][tid:com.facebook.React.JavaScript] "Error: null is not an object (evaluating 'cb.apply')
 stack:
  _invokeCallback  index.ios.bundle:7593
  <unknown>        index.ios.bundle:7656
  <unknown>        index.ios.bundle:7648
  perform          index.ios.bundle:6157
  batchedUpdates   index.ios.bundle:13786
  batchedUpdates   index.ios.bundle:4689
  <unknown>        index.ios.bundle:7647
  applyWithGuard   index.ios.bundle:882
  guardReturn      index.ios.bundle:7421
  processBatch     index.ios.bundle:7646
 URL: http://192.168.100.182:8081/index
Closes facebook#1226
Github Author: henter <[email protected]>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
@justinhj
Copy link

justinhj commented Jul 7, 2015

I've updated to the latest publicly available React native, but this crash still happens using the demo code provided.

@aphillipo
Copy link

Still seems to be broken for me too. Did this make it into the release, should I use beta/github react-native from npm?

ayushjainrksh pushed a commit to MLH-Fellowship/react-native that referenced this pull request Jul 2, 2020
* Update dependencies

* Fix CSS selector as .container has been removed
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants