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

SyncServiceImpl.isInSync() does not work with APKAM #1444

Closed
gkc opened this issue Dec 5, 2024 · 3 comments · Fixed by #1448
Closed

SyncServiceImpl.isInSync() does not work with APKAM #1444

gkc opened this issue Dec 5, 2024 · 3 comments · Fixed by #1448
Assignees
Labels
bug Something isn't working

Comments

@gkc
Copy link
Contributor

gkc commented Dec 5, 2024

Describe the bug

SyncServiceImpl.isInSync() creates a new RemoteSecondary each time it is called. The reasons for doing this are not entirely clear, given that SyncServiceImpl.create() already creates a RemoteSecondary , but that is another story.

In SyncServiceImpl.create() the enrollmentId is passed to the RemoteSecondary constructor:

    remoteSecondary ??= RemoteSecondary(
        atClient.getCurrentAtSign()!, atClient.getPreferences()!,
        atChops: atClient.atChops, enrollmentId: atClient.enrollmentId);

However in SyncServiceImpl.isInSync() it is not:

      remoteSecondary = RemoteSecondary(
          _atClient.getCurrentAtSign()!, _atClient.getPreferences()!,
          atChops: _atClient.atChops);

Authentication will then fail, since the enrollmentId must be supplied in order to authenticate with APKAM keys.

Steps to reproduce

Create a program like this:

import 'dart:io';

import 'package:at_cli_commons/at_cli_commons.dart';

Future<void> main(List<String> args) async {
  try {
    var atClient = (await CLIBase.fromCommandLineArgs(args)).atClient;
    await atClient.syncService.isInSync();
    exit(0);
  } catch (e) {
    if (e is ArgumentError) {
      print(CLIBase.argsParser.usage);
    }
    print(e);
    exit(1);
  }
}

its dependencies are

dependencies:
  at_cli_commons: ^1.3.0
  at_client: ^3.3.0

Running it with a PKAM keys file:

gary@gkc2019 example % dart bin/is_in_sync_example.dart -a @garycasey -n test
Connecting ... Connected
Is in sync? false

Running it with an APKAM keys file:

gary@gkc2019 example % dart bin/is_in_sync_example.dart -a @garycasey -k ~/@garycasey.test.mbp.atKeys -n test
Connecting ... Connected
Exception: Exception: Unable to fetch latest server commit id: Exception: Exception: Failed connecting to @garycasey. error:{"errorCode":"AT0401","errorDescription":"Exception: pkam authentication failed"}

Expected behavior

isInSync should also pass enrollmentId to the RemoteSecondary constructor

Additional context

As part of fixing this I'd also like to see whether we can eliminate isInSync's creation of its own RemoteSecondary

@gkc gkc added the bug Something isn't working label Dec 5, 2024
@XavierChanth
Copy link
Member

Looks like there should be a private _getRemoteSecondary() function, and each place where we need the remote secondary, we should call something like:

_remoteSecondary ??= _getRemoteSecondary();

@murali-shris
Copy link
Member

The reason for adding separate remote secondary for isInSync method.
#404
In the current draft PR , I have removed the logic.
Will try replicating the old isInSync bug with latest code.

@purnimavenkatasubbu
Copy link
Member

purnimavenkatasubbu commented Dec 10, 2024

Test Results

  1. . Try replicating old isInSync bug raised by Colin with sync_service_bug branch.
    AtClientManager.synchService.isInSync crashes after a few calls . #404
    Issue is not replicated.

  2. replicate the current isInSync issue with sync_service_bug branch

dart sync_test.dart -a @ purnima -n wavi -k /home/purnima/.atsign/keys/@ purnima_buzzkey.atKeys
-d vip.ve.atsign.zone
Connecting ... Connected
Exception: Exception: Unable to fetch latest server commit id: Exception: Exception: Failed connecting to @ purnima. error:{"errorCode":"AT0401","errorDescription":"Exception: pkam authentication failed"}
purnima@ purnima:~/Documents/libraries_sync_bug/at_libraries/packages/at_cli_commons/test$

  1. Re run the test with sync_service_bug branch
    dart sync_test.dart -a @ purnima -n wavi -k /home/purnima/.atsign/keys/@purnima_buzzkey.atKeys -d vip.ve.atsign.zone
    Connecting ... Connected
    is inSync : false

  2. sanity testing with buzz app and onboarding_cli with my branch

buzzLogs.txt
clitests.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants