Skip to content

fix: delete cni statefile when unable to be parsed #3551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions network/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package network

import (
"context"
"encoding/json"
"net"
"sync"
"time"
Expand Down Expand Up @@ -192,13 +193,19 @@ func (nm *networkManager) restore(isRehydrationRequired bool) error {
// Read any persisted state.
err := nm.store.Read(storeKey, nm)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to log the contents invalid and all to help assist with troubleshooting?

var syntaxErr *json.SyntaxError
if err == store.ErrKeyNotFound {
logger.Info("network store key not found")
// Considered successful.
return nil
} else if err == store.ErrStoreEmpty {
logger.Info("network store empty")
return nil
} else if errors.As(err, &syntaxErr) {
// if null chars detected or failed to parse, state is unrecoverable; delete it
logger.Error("Failed to parse corrupted state, deleting", zap.Error(err))
nm.store.Remove()
return errors.Wrap(err, "failed to parse corrupted state")
} else {
logger.Error("Failed to restore state", zap.Error(err))
return err
Expand Down
Loading