Skip to content

Commit

Permalink
remove corrupted files and return not found
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Bertschy <[email protected]>
  • Loading branch information
matthyx committed Jul 16, 2024
1 parent 1a0f658 commit 4232af7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 13 additions & 1 deletion pkg/registry/file/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4232af7

Please sign in to comment.