Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

priyanshi-yb
Copy link
Contributor

Describe the changes in this pull request

Fixing the nil pointer exception while sending the call home payload for exit/error case during initial phase of import data to source/source-replica.
fixes #2364

Describe if there are any user-facing changes

No

How was this pull request tested?

Manually

Does your PR have changes that can cause upgrade issues?

Component Breaking changes?
MetaDB No
Name registry json No
Data File Descriptor Json No
Export Snapshot Status Json No
Import Data State No
Export Status Json No
Data .sql files of tables No
Export and import data queue No
Schema Dump No
AssessmentDB No
Sizing DB No
Migration Assessment Report Json No
Callhome Json No
YugabyteD Tables No
TargetDB Metadata Tables No

@priyanshi-yb priyanshi-yb marked this pull request as ready for review March 4, 2025 05:43
Comment on lines 99 to +103
sourceDBDetails := callhome.SourceDBDetails{
DBType: tconf.TargetDBType,
DBVersion: targetDBDetails.DBVersion,
}
if targetDBDetails != nil {
sourceDBDetails.DBVersion = targetDBDetails.DBVersion
Copy link
Collaborator

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

sourceDBDetails := callhome.SourceDBDetails{
		DBType:    tconf.TargetDBType,
		DBVersion: lo.Ternary(targetDBDetails != nil,  targetDBDetails.DBVersion, ""),
}

Copy link
Contributor Author

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

Copy link
Collaborator

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

@@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the case when statsReporter will be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
Golang doesn't have try catch sort of thing, but they have combination of defer and recover to recover the program from panic state.

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

@priyanshi-yb priyanshi-yb force-pushed the priyanshi/fix-nil-pointer branch from f50dbb5 to 780f73d Compare March 4, 2025 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants