From 681541061f89fa789998433dacfb4d8bee37c327 Mon Sep 17 00:00:00 2001 From: kirillston Date: Wed, 29 May 2024 19:48:53 +0300 Subject: [PATCH 1/4] GO-3541 Async fetchGlobalName --- core/identity/ownidentity.go | 10 +++++++--- core/identity/ownidentity_test.go | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/identity/ownidentity.go b/core/identity/ownidentity.go index ab113ecaa4..0bc2697346 100644 --- a/core/identity/ownidentity.go +++ b/core/identity/ownidentity.go @@ -133,7 +133,7 @@ func (s *ownProfileSubscription) run(ctx context.Context) (err error) { s.handleOwnProfileDetails(records[0].Details) } - s.fetchGlobalName() + go s.fetchGlobalName(s.componentCtx, s.namingService) go func() { for { @@ -205,8 +205,12 @@ func (s *ownProfileSubscription) handleOwnProfileDetails(profileDetails *types.S s.enqueuePush() } -func (s *ownProfileSubscription) fetchGlobalName() { - response, err := s.namingService.GetNameByAnyId(s.componentCtx, &nameserviceproto.NameByAnyIdRequest{AnyAddress: s.myIdentity}) +func (s *ownProfileSubscription) fetchGlobalName(ctx context.Context, ns nameserviceclient.AnyNsClientService) { + if ctx == nil || ns == nil { + log.Error("error fetching global name of our own identity from Naming Service as the service is not initialized") + return + } + response, err := ns.GetNameByAnyId(ctx, &nameserviceproto.NameByAnyIdRequest{AnyAddress: s.myIdentity}) if err != nil || response == nil { log.Error("error fetching global name of our own identity from Naming Service", zap.Error(err)) return diff --git a/core/identity/ownidentity_test.go b/core/identity/ownidentity_test.go index e574e8c1c5..ccb6ca3f6c 100644 --- a/core/identity/ownidentity_test.go +++ b/core/identity/ownidentity_test.go @@ -135,6 +135,8 @@ func TestOwnProfileSubscription(t *testing.T) { err := fx.run(context.Background()) require.NoError(t, err) + time.Sleep(testBatchTimeout / 4) + fx.objectStoreFixture.AddObjects(t, []objectstore.TestObject{ { bundle.RelationKeyId: pbtypes.String(testProfileObjectId), @@ -201,6 +203,8 @@ func TestOwnProfileSubscription(t *testing.T) { err := fx.run(context.Background()) require.NoError(t, err) + time.Sleep(testBatchTimeout / 4) + fx.updateGlobalName(newName) time.Sleep(2 * testBatchTimeout) @@ -254,6 +258,8 @@ func TestOwnProfileSubscription(t *testing.T) { err := fx.run(context.Background()) require.NoError(t, err) + time.Sleep(testBatchTimeout / 4) + fx.objectStoreFixture.AddObjects(t, []objectstore.TestObject{ { bundle.RelationKeyId: pbtypes.String(testProfileObjectId), From d0bbb269a210de1dc485b32c1f7c3147537e6ec0 Mon Sep 17 00:00:00 2001 From: kirillston Date: Thu, 30 May 2024 12:33:50 +0200 Subject: [PATCH 2/4] GO-3541 Exclude mutual modification of pushTimer --- core/identity/ownidentity.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/identity/ownidentity.go b/core/identity/ownidentity.go index 0bc2697346..4f11246f7d 100644 --- a/core/identity/ownidentity.go +++ b/core/identity/ownidentity.go @@ -206,7 +206,7 @@ func (s *ownProfileSubscription) handleOwnProfileDetails(profileDetails *types.S } func (s *ownProfileSubscription) fetchGlobalName(ctx context.Context, ns nameserviceclient.AnyNsClientService) { - if ctx == nil || ns == nil { + if ns == nil { log.Error("error fetching global name of our own identity from Naming Service as the service is not initialized") return } @@ -219,7 +219,12 @@ func (s *ownProfileSubscription) fetchGlobalName(ctx context.Context, ns nameser log.Debug("globalName was not found for our own identity in Naming Service") return } - s.handleGlobalNameUpdate(response.Name) + // getting name from NS could be a long operation, so we need to check if component is still opened + if err = ctx.Err(); err != nil { + log.Error("failed to update global name of our own identity, as component context exceeded") + return + } + s.updateGlobalName(response.Name) } func (s *ownProfileSubscription) updateGlobalName(globalName string) { From 38241bfb5ce50e911868269913e4a82d2c8179bb Mon Sep 17 00:00:00 2001 From: kirillston Date: Fri, 31 May 2024 12:45:50 +0200 Subject: [PATCH 3/4] GO-3541 Move ctx check to updateGlobalName --- core/identity/ownidentity.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/identity/ownidentity.go b/core/identity/ownidentity.go index 4f11246f7d..ff002bd562 100644 --- a/core/identity/ownidentity.go +++ b/core/identity/ownidentity.go @@ -219,15 +219,14 @@ func (s *ownProfileSubscription) fetchGlobalName(ctx context.Context, ns nameser log.Debug("globalName was not found for our own identity in Naming Service") return } - // getting name from NS could be a long operation, so we need to check if component is still opened - if err = ctx.Err(); err != nil { - log.Error("failed to update global name of our own identity, as component context exceeded") - return - } s.updateGlobalName(response.Name) } func (s *ownProfileSubscription) updateGlobalName(globalName string) { + if err := s.componentCtx.Err(); err != nil { + log.Error("failed to update global name of our own identity, as component context exceeded") + return + } s.globalNameUpdatedCh <- globalName } From ae5228f9ca4589b7c9d35449d7162aeee94c7a8b Mon Sep 17 00:00:00 2001 From: kirillston Date: Fri, 31 May 2024 15:48:09 +0200 Subject: [PATCH 4/4] GO-3541 Deal with concur via select --- core/identity/ownidentity.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/identity/ownidentity.go b/core/identity/ownidentity.go index ff002bd562..760ab0599e 100644 --- a/core/identity/ownidentity.go +++ b/core/identity/ownidentity.go @@ -223,11 +223,12 @@ func (s *ownProfileSubscription) fetchGlobalName(ctx context.Context, ns nameser } func (s *ownProfileSubscription) updateGlobalName(globalName string) { - if err := s.componentCtx.Err(); err != nil { - log.Error("failed to update global name of our own identity, as component context exceeded") + select { + case <-s.componentCtx.Done(): + return + case s.globalNameUpdatedCh <- globalName: return } - s.globalNameUpdatedCh <- globalName } func (s *ownProfileSubscription) handleGlobalNameUpdate(globalName string) {