atsign-foundation / at_client_sdk

The Dart implementation of atSDK used for implementing Atsign's technology into other software
https://pub.dev/publishers/atsign.org/packages
BSD 3-Clause "New" or "Revised" License
1.46k stars 31 forks source link

AtClientManager.synchService.isInSync crashes after a few calls . #404

Closed cconstab closed 2 years ago

cconstab commented 2 years ago

Describe the bug Crashed app when checking that status of Sync between local and remote secondaries

To Reproduce Steps to reproduce the behavior: When using this code

  while (true) {
    print('sync in progress');
    var a = await atClientManager.syncService.isInSync();
    print('Are we waiting ?' + a.toString());
    sleep(const Duration(seconds: 5));
  }
  print('OK Ready');

I always get a Unhandled exception after a few cycles..

 Error : FormatException: Unexpected character (at character 1)
data:[{"atKey":"_latestnotificationid.ai6bh@ai6bh","value":"{\"id\":\"50dc4...
^

Unhandled exception:
NoSuchMethodError: The method '[]' was called on null.
Receiver: null
Tried calling: [](0)
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:68:5)
#1      SyncUtil.getLatestServerCommitId (package:at_client/src/util/sync_util.dart:87:18)
<asynchronous suspension>
#2      SyncServiceImpl._getServerCommitId (package:at_client/src/service/sync_service_impl.dart:410:27)
<asynchronous suspension>
#3      SyncServiceImpl.isInSync (package:at_client/src/service/sync_service_impl.dart:392:26)
<asynchronous suspension>
#4      main (file:///C:/Users/colin/GitHub/@company/mwc_demo/dart/iot_sender/bin/iot_sender.dart:52:13)
<asynchronous suspension>
PS C:\Users\colin\GitHub\@company\mwc_demo\dart\iot_sender> 

Looks like a low level protocol problem

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Were you using an @‎application when the bug was found?

Additional context Isthere or should there be a better way to check ?

gkc commented 2 years ago

@murali-shris please can you take a look since you're working on the sync progress listener at the moment

murali-shris commented 2 years ago

@murali-shris please can you take a look since you're working on the sync progress listener at the moment

Sure Gary.

murali-shris commented 2 years ago

root cause: The call to isInSync from the main method, interferes with a sync from server. Both share the same remote secondary. Hence we get sync verb response in the place we are expecting latest server commit Id. possible resolution: in the call to isInSync create a new remote secondary instead of reusing the remote secondary.

To be discussed in architecture call

murali-shris commented 2 years ago

Pull request https://github.com/atsign-foundation/at_client_sdk/pull/405

gkc commented 2 years ago

@cconstab the fix (#405) has been merged to trunk; can you try to reproduce please so we can verify the fix?

murali-shris commented 2 years ago

Fixed in at_client version 3.0.10

murali-shris commented 2 years ago

@cconstab can you please verify the fix in latest version of at_client

murali-shris commented 2 years ago

pending fix verification.Moving to next sprint

murali-shris commented 2 years ago

@cconstab I am closing this issue.Please re-open if you face the issue again.