diff --git a/changelog/unreleased/fix-loading-shares.md b/changelog/unreleased/fix-loading-shares.md new file mode 100644 index 0000000000..b4b77d5c33 --- /dev/null +++ b/changelog/unreleased/fix-loading-shares.md @@ -0,0 +1,5 @@ +Bugfix: Fix errors when loading shares + +We fixed a bug where loading shares and associated received shares ran into issues when handling them simultaneously. + +https://github.com/cs3org/reva/pull/2994 diff --git a/pkg/share/manager/cs3/cs3.go b/pkg/share/manager/cs3/cs3.go index e990f5acbb..7e33b5f86c 100644 --- a/pkg/share/manager/cs3/cs3.go +++ b/pkg/share/manager/cs3/cs3.go @@ -172,6 +172,7 @@ func (m *Manager) Load(ctx context.Context, shareChan <-chan *collaboration.Shar return err } + var mu sync.Mutex var wg sync.WaitGroup wg.Add(2) go func() { @@ -179,18 +180,22 @@ func (m *Manager) Load(ctx context.Context, shareChan <-chan *collaboration.Shar if s == nil { continue } + mu.Lock() if err := m.persistShare(context.Background(), s); err != nil { log.Error().Err(err).Interface("share", s).Msg("error persisting share") } + mu.Unlock() } wg.Done() }() go func() { for s := range receivedShareChan { if s.ReceivedShare != nil && s.UserID != nil { + mu.Lock() if err := m.persistReceivedShare(context.Background(), s.UserID, s.ReceivedShare); err != nil { log.Error().Err(err).Interface("received share", s).Msg("error persisting received share") } + mu.Unlock() } } wg.Done() diff --git a/pkg/storage/utils/decomposedfs/decomposedfs.go b/pkg/storage/utils/decomposedfs/decomposedfs.go index bb5d8d5856..09d8f52e0b 100644 --- a/pkg/storage/utils/decomposedfs/decomposedfs.go +++ b/pkg/storage/utils/decomposedfs/decomposedfs.go @@ -315,7 +315,7 @@ func (fs *Decomposedfs) CreateDir(ctx context.Context, ref *provider.Reference) return } if n.Exists { - return errtypes.AlreadyExists(parentRef.Path) + return errtypes.AlreadyExists(ref.Path) } if err = fs.tp.CreateDir(ctx, n); err != nil {