-
Notifications
You must be signed in to change notification settings - Fork 248
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ package network | |
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net" | ||
"sync" | ||
"time" | ||
|
@@ -192,13 +193,25 @@ func (nm *networkManager) restore(isRehydrationRequired bool) error { | |
// Read any persisted state. | ||
err := nm.store.Read(storeKey, nm) | ||
if err != nil { | ||
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)) | ||
contents, readErr := nm.store.Dump() | ||
if readErr != nil { | ||
logger.Error("Could not read corrupted state", zap.Error(readErr)) | ||
} else { | ||
logger.Info("Logging state", zap.String("stateFile", contents)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: logging corrupted state. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We log the corrupted state for debugging as per the suggestion by Michael above. Is there some drawback of doing this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for debugging as per the above reviewer's comments-- what other issues could arise from logging the corrupted state? It should only be dumped once as the statefile will be deleted afterwards. |
||
} | ||
nm.store.Remove() | ||
QxBytes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return errors.Wrap(err, "failed to parse corrupted state") | ||
} else { | ||
logger.Error("Failed to restore state", zap.Error(err)) | ||
return err | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking into this and the store's file name and contents are not accessible-- currently leaning towards just adding a method to the interface to dump the contents of the store in string format.