From 9165b7dbeb85ef50109ae6e3671dbbbcab224867 Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Wed, 16 Oct 2024 09:40:22 +0200 Subject: [PATCH] fix: shareCache concurrency panic --- .../fix-sharecache-concurrency-panic.md | 5 +++++ .../usershareprovider/usershareprovider.go | 19 ++++++++++++------- .../manager/jsoncs3/sharecache/sharecache.go | 8 +++++--- 3 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 changelog/unreleased/fix-sharecache-concurrency-panic.md diff --git a/changelog/unreleased/fix-sharecache-concurrency-panic.md b/changelog/unreleased/fix-sharecache-concurrency-panic.md new file mode 100644 index 0000000000..168dfe8dc8 --- /dev/null +++ b/changelog/unreleased/fix-sharecache-concurrency-panic.md @@ -0,0 +1,5 @@ +Bugfix: Fix ShareCache concurrency panic + +We fixed an issue where concurrently read and write operations led to a panic in the ShareCache. + +https://github.com/cs3org/reva/pull/4887 diff --git a/internal/grpc/services/usershareprovider/usershareprovider.go b/internal/grpc/services/usershareprovider/usershareprovider.go index 60433148df..3d2247a42e 100644 --- a/internal/grpc/services/usershareprovider/usershareprovider.go +++ b/internal/grpc/services/usershareprovider/usershareprovider.go @@ -535,16 +535,21 @@ func (s *service) UpdateReceivedShare(ctx context.Context, req *collaboration.Up var uid userpb.UserId _ = utils.ReadJSONFromOpaque(req.Opaque, "userid", &uid) updatedShare, err := s.sm.UpdateReceivedShare(ctx, req.Share, req.UpdateMask, &uid) - if err != nil { + switch err.(type) { + case nil: + return &collaboration.UpdateReceivedShareResponse{ + Status: status.NewOK(ctx), + Share: updatedShare, + }, nil + case errtypes.NotFound: return &collaboration.UpdateReceivedShareResponse{ - Status: status.NewInternal(ctx, "error updating received share"), + Status: status.NewNotFound(ctx, "error getting received share"), + }, nil + default: + return &collaboration.UpdateReceivedShareResponse{ + Status: status.NewInternal(ctx, "error getting received share"), }, nil } - - return &collaboration.UpdateReceivedShareResponse{ - Status: status.NewOK(ctx), - Share: updatedShare, - }, nil } func setReceivedShareMountPoint(ctx context.Context, gwc gateway.GatewayAPIClient, req *collaboration.UpdateReceivedShareRequest) (*rpc.Status, error) { diff --git a/pkg/share/manager/jsoncs3/sharecache/sharecache.go b/pkg/share/manager/jsoncs3/sharecache/sharecache.go index 3d6fbe7037..f763dee0f8 100644 --- a/pkg/share/manager/jsoncs3/sharecache/sharecache.go +++ b/pkg/share/manager/jsoncs3/sharecache/sharecache.go @@ -28,13 +28,15 @@ import ( "sync" "time" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/codes" + "golang.org/x/exp/maps" + "github.com/cs3org/reva/v2/pkg/appctx" "github.com/cs3org/reva/v2/pkg/errtypes" "github.com/cs3org/reva/v2/pkg/share/manager/jsoncs3/shareid" "github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/mtimesyncedcache" "github.com/cs3org/reva/v2/pkg/storage/utils/metadata" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" ) // name is the Tracer name used to identify this instrumentation library. @@ -246,7 +248,7 @@ func (c *Cache) List(ctx context.Context, userid string) (map[string]SpaceShareI for ssid, cached := range us.UserShares { r[ssid] = SpaceShareIDs{ - IDs: cached.IDs, + IDs: maps.Clone(cached.IDs), } } return r, nil