diff --git a/core/identity/ownidentity.go b/core/identity/ownidentity.go index ab113ecaa4..760ab0599e 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 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 @@ -215,11 +219,16 @@ func (s *ownProfileSubscription) fetchGlobalName() { log.Debug("globalName was not found for our own identity in Naming Service") return } - s.handleGlobalNameUpdate(response.Name) + s.updateGlobalName(response.Name) } func (s *ownProfileSubscription) updateGlobalName(globalName string) { - s.globalNameUpdatedCh <- globalName + select { + case <-s.componentCtx.Done(): + return + case s.globalNameUpdatedCh <- globalName: + return + } } func (s *ownProfileSubscription) handleGlobalNameUpdate(globalName string) { 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),