-
Notifications
You must be signed in to change notification settings - Fork 12
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
Fix: nil pointer exception while sending the callhome payload for import data to source/source-replica #2371
base: main
Are you sure you want to change the base?
Changes from all 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 |
---|---|---|
|
@@ -98,7 +98,9 @@ func packAndSendImportDataToSourcePayload(status string, errorMsg string) { | |
|
||
sourceDBDetails := callhome.SourceDBDetails{ | ||
DBType: tconf.TargetDBType, | ||
DBVersion: targetDBDetails.DBVersion, | ||
} | ||
if targetDBDetails != nil { | ||
sourceDBDetails.DBVersion = targetDBDetails.DBVersion | ||
} | ||
payload.SourceDBDetails = callhome.MarshalledJsonString(sourceDBDetails) | ||
|
||
|
@@ -112,7 +114,7 @@ func packAndSendImportDataToSourcePayload(status string, errorMsg string) { | |
|
||
importDataPayload.Phase = importPhase | ||
|
||
if importPhase != dbzm.MODE_SNAPSHOT { | ||
if importPhase != dbzm.MODE_SNAPSHOT && statsReporter != nil { | ||
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. what is the case when statsReporter will be null? 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. It can be nil until it is initialized. If there is any failure or exit before that, this function will try to send the payload, and we can get a nil pointer exception in such a case. 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. Got it. I was think can we introduce some sort of error handling here. I think for this codepath it makes sense to handle panic, not think about other places if we can use this. what do you guys think? @makalaaneesh @priyanshi-yb 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. |
||
importDataPayload.EventsImportRate = statsReporter.EventsImportRateLast3Min | ||
importDataPayload.TotalImportedEvents = statsReporter.TotalEventsImported | ||
} | ||
|
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.
maybe use a ternary operator for the check
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.
can't do this; it doesn't work if we do nil check in this function as it still tries to run the if clause. refer https://go.dev/play/p/sgeATTvMgMP
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.
Interesting.
So this is because Go follows strict/eager evaluation of function argument