atsign-foundation / at_libraries

Support libraries & dependencies for Atsign's technology
https://pub.dev/publishers/atsign.org/packages
BSD 3-Clause "New" or "Revised" License
38 stars 11 forks source link

Race condition in AtLookupImpl._process #140

Closed gkc closed 2 years ago

gkc commented 2 years ago

Describe the bug

To Reproduce

Expected behaviour

Fixed by #139

murali-shris commented 2 years ago

import 'dart:io';

import 'package:at_client/at_client.dart'; import 'package:at_client/src/manager/at_client_manager.dart'; import 'package:at_utils/at_logger.dart';

import 'dart:convert'; import 'dart:typed_data'; import 'package:crypto/crypto.dart';

void main() async { AtSignLogger.root_level = 'finest'; final atSign = 'alice'; var atClientManager = await AtClientManager.getInstance() .setCurrentAtSign(atSign, 'wavi', _getPreference()); try { while (true) { print('sync in progress'); var a = await atClientManager.syncService.isInSync(); print('Are we waiting ?' + a.toString()); sleep(Duration(seconds: 5)); } } on Exception catch(e, trace) { print(e); print(trace); } print('OK Ready'); }

AtClientPreference _getPreference() { var preference = AtClientPreference(); preference.hiveStoragePath = '/home/murali/work/2020/hive/client'; preference.commitLogPath = '/home/murali/work/2020/hive/client/commit'; preference.isLocalStoreRequired = true; preference.privateKey = ''; preference.rootDomain = 'root.atsign.org'; var hashFile = _getShaForAtSign('@zathura97tall'); preference.keyStoreSecret = _getKeyStoreSecret( '/home/murali/work/2020/hive/client/' + hashFile + '.hash'); return preference;

}

List _getKeyStoreSecret(String filePath) { var hiveSecretString = File(filePath).readAsStringSync(); var secretAsUint8List = Uint8List.fromList(hiveSecretString.codeUnits); return secretAsUint8List; }

String _getShaForAtSign(String atsign) { var bytes = utf8.encode(atsign); return sha256.convert(bytes).toString(); }

murali-shris commented 2 years ago

@gkc above code doesn't complete successfully with trunk branch of at_client pointing to your branch of at_lookup quickFixAtLookupRaceCondition In _processSyncRequests() _syncInProgress = true; final serverCommitId = await _getServerCommitId();// stats:3 request probably is sent(unable to confirm since server has only INFO logs). The response is not received and _syncInProgress never gets set to false.

murali-shris commented 2 years ago

@gkc above code doesn't complete successfully with trunk branch of at_client pointing to your branch of at_lookup quickFixAtLookupRaceCondition In _processSyncRequests() _syncInProgress = true; final serverCommitId = await _getServerCommitId();// stats:3 request probably is sent(unable to confirm since server has only INFO logs). The response is not received and _syncInProgress never gets set to false.

@gkc after running the tests multiple times I figured that issue happens even without your code changes..Issue requires a fix in SyncServiceImpl.

gkc commented 2 years ago

Yep it's unrelated

gkc commented 2 years ago

Closing - fixed by #139 and new at_lookup package 3.0.8 published