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: data race for get jobs map #558

Merged
merged 1 commit into from
Sep 4, 2023

Conversation

rfyiamcool
Copy link

summary

data race for get jobsMap.

defer s.jobsMutex.RUnlock()
jobs := make(map[uuid.UUID]*Job, len(s.jobs))
for id, job := range s.jobs {
jobs[id] = job
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the data race on the map object or the jobs inside the map?

Copy link
Author

Choose a reason for hiding this comment

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

😁 A coroutine calls the Jobs api to obtain jobs, and then reads them. Another coroutine modifies the jobs dictionary? In this way, golang will cause error messages for concurrent map reading and writing.

@JohnRoesler JohnRoesler merged commit fd26595 into go-co-op:main Sep 4, 2023
6 checks passed
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.

None yet

2 participants