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

Make a copy of MachineInfo in GetMachineInfo() #2490

Merged
merged 1 commit into from
Apr 10, 2020

Conversation

tedyu
Copy link
Collaborator

@tedyu tedyu commented Apr 10, 2020

Fixes #2487

The data race was due to manager.machineInfo being read after manager#GetMachineInfo() returns.

This PR makes a copy of MachineInfo and returns the pointer to the copy.

@dashpole
Copy link
Collaborator

/retest

@tedyu tedyu force-pushed the mach-info-copy branch 2 times, most recently from 2dd055c to 8ac1498 Compare April 10, 2020 16:21
@tedyu
Copy link
Collaborator Author

tedyu commented Apr 10, 2020

I tried to adapt assert.JSONEq()

func JSONEq(expected string, actual string) bool {
	var expectedJSONAsInterface, actualJSONAsInterface interface{}

	if err := json.Unmarshal([]byte(expected), &expectedJSONAsInterface); err != nil {
		return false
	}

	if err := json.Unmarshal([]byte(actual), &actualJSONAsInterface); err != nil {
		return false
	}

	return expectedJSONAsInterface == actualJSONAsInterface
}

But the json interface comparison needed more work.

I chose to compare strings in the current PR since we have the string form of topology JSON and expected JSON.

Signed-off-by: Ted Yu <yuzhihong@gmail.com>
Copy link
Collaborator

@dashpole dashpole left a comment

Choose a reason for hiding this comment

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

lgtm

@dashpole dashpole merged commit 3b7947f into google:master Apr 10, 2020
bobbypage added a commit that referenced this pull request Nov 5, 2020
Cherry-pick #2490  Make a copy of MachineInfo in GetMachineInfo() to v0.35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible race detected
2 participants