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

Replace tag map with thread safe sync.map #212

Merged
merged 4 commits into from
Aug 22, 2021

Conversation

djenriquez
Copy link

What does this do?

This PR replaces that uniqueTag map with the sync.Map struct which allows safe concurrent operations against the map. Before this, scheduled jobs that executed on the same schedule were prone to causing a "concurrent map" panic.

Have you included tests for your changes?

Tests have been updated to properly use the sync.map.

Notes

This change should produce a no-op, just fixes the potential panic from jobs scheduled at the same time that require uniqueTags.

scheduler.go Outdated
if s.tags != nil {
s.TagsUnique()
}
s.TagsUnique()
Copy link
Contributor

Choose a reason for hiding this comment

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

We only want to set the tags to unique if they were originally set on the scheduler. So this should probably still have a if check to say if not false then set to an new empty sync map. Am I missing something with how this map works or anything?

Copy link
Author

Choose a reason for hiding this comment

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

Ah, I see, the purpose of this originally was to reinstantiate the tag map to clear out the tags. Now that it is using a sync.Map, it would need to go through and delete the items within.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed and verified with TDD.

@JohnRoesler JohnRoesler merged commit f0d857f into go-co-op:master Aug 22, 2021
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.

2 participants