Add additional unwrap code in ToStatusError() gRPC error handler #434
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
Add additional unwrap code in
TostatusError()
ingrpchelper/status.go
which unwrap’s error until cause is set to base inner error.This additional code is needed to avoid
errorToCode
map’shash of unhashable type
runtime error which leads to server panic.This will prevent Yorkie server(Yorkie SaaS API) to panic(service unavailable) on unexpected error triggered by user.
Below is
ToStatusError()
’s parameter,err
’s inner stacks(errors)Parameter
err
needs to be unwrapped to base inner error. If not,errorToCode[cause]
map (maps error to gRPC status code) will get invalid key for map likeerrorToCode[mongo.CommandError]
which will lead to serverpanic: runtime error: hash of unhashable type mongo.CommandError
.This runtime error will occur when parameter
err
has nested errors (ex:mongo.CommandError
)Which issue(s) this PR fixes:
No issue is related.
Special notes for your reviewer:
This PR started with server log provided by @hackerwins on discord thread on unexpected server down issue.
Also, I'm not sure about the initial cause of this error, which makes
connection(localhost:27017[-12]) incomplete read of message header: context canceled
error. I'll keep trying to reproduce this issue in code ASAP.Does this PR introduce a user-facing change?:
Additional documentation:
Checklist: