Skip to content
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

Realm for React Native not work offline #6554

Closed
mancioshell opened this issue Mar 15, 2024 · 13 comments
Closed

Realm for React Native not work offline #6554

mancioshell opened this issue Mar 15, 2024 · 13 comments

Comments

@mancioshell
Copy link

mancioshell commented Mar 15, 2024

How frequently does the bug occur?

Always

Description

Hi, i’m using realm for a react native application.
I receive SyncError: Failed to connect to sync: Host not found (authoritative) error when turn off wifi. But i have read mongo realm is offline first…

I open realm like this:

function AuthProvider() {
  const [visible, setVisible] = useState<boolean>(false);
  const [error, setError] = useState<string>('');

  const user = useUser();
  console.log('user', user);

  const realmAccessBehavior: Realm.OpenRealmBehaviorConfiguration = {
    type: Realm.OpenRealmBehaviorType.DownloadBeforeOpen,
    timeOutBehavior: Realm.OpenRealmTimeOutBehavior.OpenLocalRealm,
    timeOut: 3000,
  };

  return (
    <RealmProvider
      schema={[
        Invoice,
        Operator,
        Customer,
        Report,
        ReportDetail,
        Manpower,
        Material,
        RightToCall,
      ]}
      sync={{
        flexible: true,
        newRealmFileBehavior: realmAccessBehavior,
        existingRealmFileBehavior: realmAccessBehavior,
        initialSubscriptions: {
          update(subs, realm) {
            subs.add(realm.objects(Invoice));
            subs.add(realm.objects(Customer));
            subs.add(realm.objects(Operator));
            subs.add(realm.objects(Report));
          },
          rerunOnOpen: true,
        },
        onError: (_session, err) => {
          console.log('error', err);
          setError(err.message);
          setVisible(true);
        },
      }}>
      <App />
      <ErrorDialog
        errorTitle="Errore di Sincronizzazione"
        errorMsg={error}
        visible={visible}
        setVisible={setVisible}
      />
    </RealmProvider>
  );
}

Stacktrace & log output

03-14 16:25:28.255 6242 6302 W ReactNativeJS:
03-14 16:25:28.255 6242 6302 W ReactNativeJS: URL: 10.0.2.2:8081
03-14 16:25:28.255 6242 6302 W ReactNativeJS:
03-14 16:25:28.255 6242 6302 W ReactNativeJS: Error: Software caused connection abort
03-14 16:25:28.389 6242 6302 I ReactNativeJS: 'Connection state changed', 'active'
03-14 16:25:29.083 6242 6302 I ReactNativeJS: 'Connection state changed', 'active'
03-14 16:25:29.099 6242 6302 E ReactNativeJS: [error] Failed to resolve 'ws.eu-west-1.aws.realm.mongodb.com:443': Host not found (authoritative)
03-14 16:25:29.100 6242 6302 I ReactNativeJS: 'Connection state changed', 'active'
03-14 16:25:29.101 6242 6302 I ReactNativeJS: 'error', { [SyncError: Failed to connect to sync: Host not found (authoritative)]
03-14 16:25:29.101 6242 6302 I ReactNativeJS: name: 'SyncError',
03-14 16:25:29.101 6242 6302 I ReactNativeJS: isOk: false,
03-14 16:25:29.101 6242 6302 I ReactNativeJS: reason: 'Failed to connect to sync: Host not found (authoritative)',
03-14 16:25:29.101 6242 6302 I ReactNativeJS: code: 1034,
03-14 16:25:29.101 6242 6302 I ReactNativeJS: category: 'UNKNOWN',
03-14 16:25:29.101 6242 6302 I ReactNativeJS: logUrl: '',
03-14 16:25:29.101 6242 6302 I ReactNativeJS: userInfo: {},
03-14 16:25:29.101 6242 6302 I ReactNativeJS: isFatal: false }
03-14 16:25:29.104 6242 6302 I ReactNativeJS: 'user', { listeners:
03-14 16:25:29.104 6242 6302 I ReactNativeJS: { listeners: {},
03-14 16:25:29.104 6242 6302 I ReactNativeJS: options: { add: [Function: add], remove: [Function: remove] } },
03-14 16:25:29.104 6242 6302 I ReactNativeJS: internal: {},
03-14 16:25:29.104 6242 6302 I ReactNativeJS: app:
03-14 16:25:29.104 6242 6302 I ReactNativeJS: { listeners:
03-14 16:25:29.104 6242 6302 I ReactNativeJS: { listeners: {},
03-14 16:25:29.104 6242 6302 I ReactNativeJS: options: { add: [Function: add], remove: [Function: remove] } },
03-14 16:25:29.104 6242 6302 I ReactNativeJS: internal: {} },
03-14 16:25:29.104 6242 6302 I ReactNativeJS: cachedProfile: undefined }
03-14 16:25:29.323 6242 6302 I ReactNativeJS: 'user', { listeners:
03-14 16:25:29.323 6242 6302 I ReactNativeJS: { listeners: {},
03-14 16:25:29.323 6242 6302 I ReactNativeJS: options: { add: [Function: add], remove: [Function: remove] } },
03-14 16:25:29.323 6242 6302 I ReactNativeJS: internal: {},
03-14 16:25:29.323 6242 6302 I ReactNativeJS: app:
03-14 16:25:29.323 6242 6302 I ReactNativeJS: { listeners:
03-14 16:25:29.323 6242 6302 I ReactNativeJS: { listeners: {},
03-14 16:25:29.323 6242 6302 I ReactNativeJS: options: { add: [Function: add], remove: [Function: remove] } },
03-14 16:25:29.323 6242 6302 I ReactNativeJS: internal: {} },
03-14 16:25:29.323 6242 6302 I ReactNativeJS: cachedProfile: undefined }

Can you reproduce the bug?

Always

Reproduction Steps

  • Start application in an Emulator.
  • Go offline, disabling wifi

Version

0.6.2

What services are you using?

Atlas Device Sync

Are you using encryption?

No

Platform OS and version(s)

Windows 10, React Native, Android 14

Build environment

adb logcat

Cocoapods version

No response

Copy link

sync-by-unito bot commented Mar 15, 2024

➤ PM Bot commented:

Jira ticket: RJS-2759

@kneth
Copy link
Contributor

kneth commented Mar 17, 2024

Host not found (authoritative) means you are offline. It is a bit confusing that the sync client reports it as an error.

From the title of the issue, it sounds like you are experiencing a variation of realm/realm-core#7349. We are actively working on a fix.

@mancioshell
Copy link
Author

mancioshell commented Mar 22, 2024

@kneth is it possible to do a workaround in the meanwhile you have done the fix? i need to work in offline mode, but unfortunately the app crash when i receive the error.

@mancioshell
Copy link
Author

For anyone has my same problem, i have downgraded the peerDependency realm to 11.10.2 and it works like a charm.

@riohifi
Copy link

riohifi commented Mar 30, 2024

const behaviorConfiguration = {
type: OpenRealmBehaviorType.OpenImmediately,
timeOut: 3000,
timeOutBehavior: OpenRealmTimeOutBehavior.OpenLocalRealm,
};

OpenImmediately not DownloadBeforeOpen then works

@mancioshell
Copy link
Author

@riohifi Not for me. I have already try this configuration without success. I have solved only downgrading version.

@kneth
Copy link
Contributor

kneth commented Apr 2, 2024

The fix is in [v12.7.0-rc.0][https://github.com/realm/realm-js/releases/tag/v12.7.0-rc.0)

@sync-by-unito sync-by-unito bot closed this as completed Apr 2, 2024
@mancioshell
Copy link
Author

@kneth i have update to 12.7.9-rc.0 but now if i open the app when offline, i receive this error which cause the crash of the app:

04-04 17:43:24.278 32030 32096 E ReactNativeJS: [Realm.App - error] App: request location failed (CustomError -1): request to https://realm.mongodb.com/api/client/v2.0/app/easy-report-gmzgp/location failed, reason: Network request failed

@mancioshell
Copy link
Author

please reopen the issue

@vatsal-gadhiya-searce
Copy link

I am getting the same issues in react native 0.73.1 app, running 12.5.0.

SyncError: Failed to connect to sync: Host not found (authoritative)
[error] Failed to resolve 'ws.eu-west-2.aws.realm.mongodb.com:443': Host not found (authoritative)

Is it resolved anywhere?

@Christiangsn
Copy link

Is it resolved anywhere??

@vatsal-gadhiya-searce
Copy link

@Christiangsn I mean I am not sure if it is breaking anything or not in our app. But it comes through a bugsnag logs in our react native application using realm.

@Christiangsn
Copy link

@Christiangsn I mean I am not sure if it is breaking anything or not in our app. But it comes through a bugsnag logs in our react native application using realm.

Should I just ignore the error log? Because I noticed that when the internet comes back, it reconnects automatically... Another point, how can I synchronize the data? Do you have an example?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants