-
Notifications
You must be signed in to change notification settings - Fork 25k
[GeoLocation] invalidate timer after success or error callback #1226
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
Conversation
|
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. |
|
@ide yeah, that's a great idea. |
|
@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. |
|
@ide thanks. code updated. :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
|
Left one small comment if you want to update it but will mark this as accepted. |
|
updated. |
|
@vjeux if I say: |
|
You need it in its own line. It actually may work with you since you have a fb employee vc |
|
@facebook-github-bot import |
|
Looking forward to see this land. 👍 |
There was a problem hiding this comment.
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 (
|
Thanks @henter. This looks fine to me. |
|
@facebook-github-bot import |
|
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.
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
|
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 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 |
|
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/index Closes facebook#1226 Github Author: henter <[email protected]> Test Plan: Imported from GitHub, without a `Test Plan:` line.
|
I've updated to the latest publicly available React native, but this crash still happens using the demo code provided. |
|
Still seems to be broken for me too. Did this make it into the release, should I use beta/github react-native from npm? |
* Update dependencies * Fix CSS selector as .container has been removed
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