-
Notifications
You must be signed in to change notification settings - Fork 52
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
Recover from potential panic when doing map to JSON serialization #161
Recover from potential panic when doing map to JSON serialization #161
Conversation
…c-gnmi into panic_recover_and_logging
sonic_data_client/db_client.go
Outdated
jv, err := emitJSON(&msi) | ||
if err != nil { | ||
log.V(2).Infof("emitJSON err %s for %v", err, msi) | ||
return nil, fmt.Errorf("emitJSON err %s for %v", err, msi) | ||
} | ||
if jv == nil { // json is nil because of potential panic happen | ||
return nil, fmt.Errorf("emitJSON failed due to panic") |
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.
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.
The idea here is that on 823, both the json value and the err value would be nil, since if emitJSON has panicked and we have recovered, the values of jv and err would be the zero values which is nil. I can instead say "emitJSON was unable to grab json value of map due to potential panic". In other cases where emitJSON would have failed to get json value we would see that err != nil.
Tried it on lab device, we can see recover from panic:
|
…nic-net#161) It is possible that in some edge cases, json.Marshal is unable to serialize map to JSON and panics. I am adding some additional logging at a higher log level and the ability for the function to recover from the panic with a deferred recover function. Add deferred recover function when JSON serialization is done and drop the query when unable to provide a JSON to gnmi TypedValue. Add additional logging to give more context of state of map as well as data retrieved from Redis. UT
…nic-net#161) It is possible that in some edge cases, json.Marshal is unable to serialize map to JSON and panics. I am adding some additional logging at a higher log level and the ability for the function to recover from the panic with a deferred recover function. Add deferred recover function when JSON serialization is done and drop the query when unable to provide a JSON to gnmi TypedValue. Add additional logging to give more context of state of map as well as data retrieved from Redis. UT
Recover from potential panic when doing map to JSON serialization (#161)
…nic-net#161) It is possible that in some edge cases, json.Marshal is unable to serialize map to JSON and panics. I am adding some additional logging at a higher log level and the ability for the function to recover from the panic with a deferred recover function. Add deferred recover function when JSON serialization is done and drop the query when unable to provide a JSON to gnmi TypedValue. Add additional logging to give more context of state of map as well as data retrieved from Redis. UT
Why I did it
ADO: 25341563
It is possible that in some edge cases, json.Marshal is unable to serialize map to JSON and panics. I am adding some additional logging at a higher log level and the ability for the function to recover from the panic with a deferred recover function.
How I did it
Add deferred recover function when JSON serialization is done and drop the query when unable to provide a JSON to gnmi TypedValue. Add additional logging to give more context of state of map as well as data retrieved from Redis.
How to verify it
UT
Which release branch to backport (provide reason below if selected)
Description for the changelog
Link to config_db schema for YANG module changes
A picture of a cute animal (not mandatory but encouraged)