Uh oh!
There was an error while loading. Please reload this page.
[GeoLocation] invalidate timer after success or error callback - #1226
[GeoLocation] invalidate timer after success or error callback#1226henter wants to merge 1 commit into
Conversation
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
commented
May 11, 2015
@ide yeah, that's a great idea. |
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)?
In 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
commented
May 15, 2015
@ide thanks. code updated. :-) |
There was a problem hiding this comment.
Slightly prefer _timeoutTimer.valid since it's documented that way here: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/index.html#//apple_ref/occ/instp/NSTimer/valid
ide
commented
May 15, 2015
Left one small comment if you want to update it but will mark this as accepted. |
henter
commented
May 15, 2015
updated. |
ide
commented
May 15, 2015
@vjeux if I say: |
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
commented
May 15, 2015
@facebook-github-bot import |
reconbot
commented
May 18, 2015
Looking forward to see this land. 👍 |
There was a problem hiding this comment.
nit: space after if and space after (
henter
commented
May 20, 2015
ide
commented
May 20, 2015
Thanks @henter. This looks fine to me. |
vjeux
commented
May 20, 2015
@facebook-github-bot import |
facebook-github-bot
commented
May 20, 2015
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. |
There was a problem hiding this comment.
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
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. |
sahrens
commented
May 22, 2015
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 |
sahrens
commented
May 23, 2015
Cool, thanks - I'll bring this in.
|
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/indexClosesreact#1226 Github Author: henter <henter@henter.me> Test Plan: Imported from GitHub, without a `Test Plan:` line.
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
commented
Aug 28, 2015
Still seems to be broken for me too. Did this make it into the release, should I use beta/github react-native from npm? |
Just trying to getCurrentPosition , and found the
errorBlockof location request in timeout handler would cause red error like this: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
errorBlockshould 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