From 1f520d1833aa0add95fb0a58b5536c322e125eb5 Mon Sep 17 00:00:00 2001 From: Roman Perekhod Date: Mon, 14 Oct 2024 19:40:39 +0200 Subject: [PATCH] Fix OCM upload crush --- changelog/unreleased/fix-ocm-upload-crush.md | 6 ++++++ pkg/ocm/storage/received/upload.go | 20 ++++++++++++-------- pkg/rhttp/datatx/manager/tus/tus.go | 4 ++++ 3 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 changelog/unreleased/fix-ocm-upload-crush.md diff --git a/changelog/unreleased/fix-ocm-upload-crush.md b/changelog/unreleased/fix-ocm-upload-crush.md new file mode 100644 index 0000000000..6cf2fd2f77 --- /dev/null +++ b/changelog/unreleased/fix-ocm-upload-crush.md @@ -0,0 +1,6 @@ +Bugfix: Fix OCM upload crush + +We fixed an issue where a federated instance crashed when uploading a file to a remote folder. +Fixed the cleanup blob and meta of the uploaded files. + +https://github.com/cs3org/reva/pull/4884 diff --git a/pkg/ocm/storage/received/upload.go b/pkg/ocm/storage/received/upload.go index 951bec8992..05556ede47 100644 --- a/pkg/ocm/storage/received/upload.go +++ b/pkg/ocm/storage/received/upload.go @@ -88,6 +88,8 @@ func (d *driver) Upload(ctx context.Context, req storage.UploadRequest, _ storag return &provider.ResourceInfo{}, err } + defer cleanup(&upload{Info: info}) + client, _, rel, err := d.webdavClient(ctx, nil, &provider.Reference{ Path: filepath.Join(info.MetaData["dir"], info.MetaData["filename"]), }) @@ -297,6 +299,7 @@ func (u *upload) FinishUpload(ctx context.Context) error { } } + defer cleanup(u) // compare if they match the sent checksum // TODO the tus checksum extension would do this on every chunk, but I currently don't see an easy way to pass in the requested checksum. for now we do it in FinishUpload which is also called for chunked uploads if u.Info.MetaData["checksum"] != "" { @@ -316,7 +319,6 @@ func (u *upload) FinishUpload(ctx context.Context) error { err = errtypes.BadRequest("unsupported checksum algorithm: " + parts[0]) } if err != nil { - u.cleanup() return err } } @@ -336,7 +338,6 @@ func (u *upload) FinishUpload(ctx context.Context) error { Path: filepath.Join(u.Info.MetaData["dir"], u.Info.MetaData["filename"]), }) if err != nil { - u.cleanup() return err } @@ -358,13 +359,8 @@ func (u *upload) FinishUpload(ctx context.Context) error { return client.WriteStream(rel, f, 0) } -func (u *upload) cleanup() { - _ = os.Remove(u.BinPath()) - _ = os.Remove(u.InfoPath()) -} - func (u *upload) Terminate(ctx context.Context) error { - u.cleanup() + cleanup(u) return nil } @@ -403,3 +399,11 @@ func (u *upload) checkHash(expected string, h hash.Hash) error { } return nil } + +func cleanup(u *upload) { + if u == nil { + return + } + _ = os.Remove(u.BinPath()) + _ = os.Remove(u.InfoPath()) +} diff --git a/pkg/rhttp/datatx/manager/tus/tus.go b/pkg/rhttp/datatx/manager/tus/tus.go index 829440ecaf..bb724c5229 100644 --- a/pkg/rhttp/datatx/manager/tus/tus.go +++ b/pkg/rhttp/datatx/manager/tus/tus.go @@ -136,6 +136,10 @@ func (m *manager) Handler(fs storage.FS) (http.Handler, error) { if err != nil { appctx.GetLogger(context.Background()).Error().Err(err).Str("session", ev.Upload.ID).Msg("failed to list upload session") } else { + if len(ups) < 1 { + appctx.GetLogger(context.Background()).Error().Str("session", ev.Upload.ID).Msg("upload session not found") + continue + } up := ups[0] executant := up.Executant() ref := up.Reference()