From 4232af7ab33c37a1db66dfe19cc1feab0df6e328 Mon Sep 17 00:00:00 2001 From: Matthias Bertschy Date: Tue, 16 Jul 2024 07:42:04 +0200 Subject: [PATCH] remove corrupted files and return not found Signed-off-by: Matthias Bertschy --- build/Dockerfile | 2 +- pkg/registry/file/storage.go | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index ee2824c21..174f5a6d8 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM golang:1.22-bullseye as builder +FROM --platform=$BUILDPLATFORM golang:1.22-bullseye AS builder ENV GO111MODULE=on CGO_ENABLED=0 WORKDIR /work diff --git a/pkg/registry/file/storage.go b/pkg/registry/file/storage.go index 6446495ef..125762362 100644 --- a/pkg/registry/file/storage.go +++ b/pkg/registry/file/storage.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "fmt" + "io" "os" "path/filepath" "reflect" @@ -305,7 +306,18 @@ func (s *StorageImpl) get(ctx context.Context, key string, opts storage.GetOptio decoder := gob.NewDecoder(payloadFile) err = decoder.Decode(objPtr) if err != nil { - logger.L().Ctx(ctx).Error("Get - json unmarshal failed", helpers.Error(err), helpers.String("key", key)) + if errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, io.EOF) { + // irrecoverable error, delete both files + _ = s.appFs.Remove(makeMetadataPath(p)) + _ = s.appFs.Remove(makePayloadPath(p)) + logger.L().Debug("Get - gob unexpected EOF, removed files", helpers.String("key", key)) + if opts.IgnoreNotFound { + return runtime.SetZeroValue(objPtr) + } else { + return storage.NewKeyNotFoundError(key, 0) + } + } + logger.L().Ctx(ctx).Error("Get - gob unmarshal failed", helpers.Error(err), helpers.String("key", key)) return err } return nil