Skip to content

Commit

Permalink
fix: In setHeadsForGroup, wait for Replicator().Load to set _remoteHe…
Browse files Browse the repository at this point in the history
…ads.

Signed-off-by: Jeff Thompson <[email protected]>
  • Loading branch information
jefft0 committed Feb 22, 2023
1 parent 25edabf commit eb08351
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions orbitdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"berty.tech/go-orbit-db/baseorbitdb"
"berty.tech/go-orbit-db/iface"
"berty.tech/go-orbit-db/pubsub/pubsubcoreapi"
"berty.tech/go-orbit-db/stores"
"berty.tech/weshnet/internal/datastoreutil"
"berty.tech/weshnet/pkg/cryptoutil"
"berty.tech/weshnet/pkg/errcode"
Expand Down Expand Up @@ -319,8 +320,28 @@ func (s *BertyOrbitDB) setHeadsForGroup(ctx context.Context, g *protocoltypes.Gr
for i, h := range metaHeads {
metaHeadsEntries[i] = &entry.Entry{Hash: h}
}

if len(metaHeads) == 0 {
return nil
}

chSub, err := metaImpl.EventBus().Subscribe(new(stores.EventReplicated))
if err != nil {
// something is really wrong if this happens, so better return an error
return fmt.Errorf("unable to subscribe to EventReplicated")
}
defer chSub.Close()

// start to load metadata heads
metaImpl.Replicator().Load(ctx, metaHeadsEntries)

// wait for load to finish
select {
case <-chSub.Out():
case <-s.ctx.Done():
return s.ctx.Err()
}

return nil
}

Expand Down

0 comments on commit eb08351

Please sign in to comment.