Skip to content

Commit

Permalink
fix(remote-config, ios): workaround firebase-ios-sdk#11458 until SDK …
Browse files Browse the repository at this point in the history
…v10.12.0

the impact of the workaround is that on iOS, if you subscribe to remote-config
realtime updates at all, the web socket to listen for updates will be opened and
never closed, even if you unsubscribe all listeners

this should be reverted when 10.12.0 is adopted
  • Loading branch information
mikehardy committed Jun 22, 2023
1 parent 90fc7b7 commit 8c75849
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/remote-config/usage/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ in applications that attach one or more listeners for them.
### Known Issues

1. **_Handle errors / retry in callback_** During testing here in react-native-firebase, we frequently received the "config_update_not_fetched" error when performing updates and fetching them rapidly. This may not occur in normal usage but be sure to include error handling code in your callback. If this error is raised, you should be able to fetch and activate the new config template with retries after a timeout. Tracked as https://github.com/firebase/firebase-ios-sdk/issues/11462 and a fix is anticipated in firebase-ios-sdk 10.12.0
1. **_iOS web socket will never close_** During testing here in react-native-firebase, we identified a problem in firebase-ios-sdk where native listeners are not removed when you attempt to unsubscribe them, resulting in more update events than expected. As a temporary workaround to avoid the issue, we create a native listener on iOS the first time you subscribe to realtime update events, and we never remove the listener, even if you unsubscribe it. That means the web socket will never close once opened. This is tracked as https://github.com/firebase/firebase-ios-sdk/issues/11458 and a fix is anticipated in firebase-ios-sdk 10.12.0

Here is an example of how to use the feature, with comments emphasizing the key points to know:

Expand Down
8 changes: 7 additions & 1 deletion packages/remote-config/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,13 @@ class FirebaseConfigModule extends FirebaseModule {
}
subscription.remove();
this._configUpdateListenerCount--;
if (this._configUpdateListenerCount === 0) {
// In firebase-ios-sdk, it appears listener removal fails, so our native listeners accumulate
// if we try to remove them. Temporarily allow iOS native listener to stay active forever after
// first subscription for an app, until issue #11458 in firebase-ios-sdk repo is resolved.
// react-native-firebase native subscribe code won't add multiple native listeners for same app,
// so this prevents listener accumulation but means the web socket on iOS will never close.
// TODO: Remove when firebase-ios-sdk 10.12.0 is adopted, the PR to fix it should be included
if (this._configUpdateListenerCount === 0 && Platform.OS !== 'ios') {
this.native.removeConfigUpdateRegistration();
}
};
Expand Down

0 comments on commit 8c75849

Please sign in to comment.