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 initial sync race #208

Merged
merged 1 commit into from
Mar 6, 2020
Merged

Fix initial sync race #208

merged 1 commit into from
Mar 6, 2020

Conversation

lkysow
Copy link
Member

@lkysow lkysow commented Feb 13, 2020

A race condition was occurring where we would delete services via the
watchReapableServices function if Sync wasn't called fast enough by
resource.go. This occurred because watchReapableServices makes a
call to the catalog and then deletes everything with a k8s tag that
isn't in its s.services map. If Sync isn't called, then this map
is empty and so it tries to delete everything.
I've solved this by blocking until Sync is first called.

Closes #191

@lkysow lkysow force-pushed the sync-catalog-tests branch 2 times, most recently from bb115b6 to 8be4a97 Compare February 13, 2020 22:12
@lkysow lkysow force-pushed the fix-init-race branch 3 times, most recently from 660aaa6 to 29ec319 Compare February 13, 2020 22:26
@lkysow lkysow added area/sync Related to catalog sync type/bug Something isn't working labels Feb 13, 2020
@lkysow
Copy link
Member Author

lkysow commented Feb 18, 2020

@ashangit sorry I didn't see your PR #191 before putting this one up. I think this PR accomplishes the same fix but instead of adding a new GetAllServices method it waits for Sync to be called. Does this look like it should work for you?

@ashangit
Copy link

thks @lkysow looks good to me

@lkysow lkysow force-pushed the fix-init-race branch 3 times, most recently from 7c43b7e to 27472e2 Compare March 2, 2020 19:55
@lkysow lkysow changed the base branch from sync-catalog-tests to master March 2, 2020 20:00
@lkysow lkysow marked this pull request as ready for review March 2, 2020 20:00
@lkysow lkysow requested review from a team and adilyse March 2, 2020 20:00
Copy link
Contributor

@adilyse adilyse left a comment

Choose a reason for hiding this comment

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

Looks good! Left a recommendation for clarification in a comment and clearer timing in the test.

Comment on lines 173 to 174
// Create a service directly in Consul. Since it was created directly we
// expect it to be deleted but not until the initial sync is performed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Create a service directly in Consul. Since it was created directly we
// expect it to be deleted but not until the initial sync is performed.
// Create a service directly in Consul. Since it was created on the
// synthetic sync node and has the sync-associated tag, we expect
// it to be deleted but not until the initial sync is performed.

A service needs the sync tag and to be registered on the sync node or the sync process would ignore it.

require.NoError(t, err)

// We wait until the syncer has had the time to delete the service.
time.Sleep(200 * time.Millisecond)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like we might run into edge cases having this value exactly equal the SyncPeriod in the test ConsulSyncer. What about setting up the ConsulSyncer with an even smaller interval?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! Great idea. I didn't like this sleep but a retry loop doesn't work because it might run through before syncFull has run :D

A race condition was occurring where we would delete services via the
`watchReapableServices` function if `Sync` wasn't called fast enough by
`resource.go`. This occurred because `watchReapableServices` makes a
call to the catalog and then deletes everything with a k8s tag that
isn't in its `s.services` map. If `Sync` isn't called, then this map
is empty and so it tries to delete everything.
I've solved this by blocking until `Sync` is first called.
@lkysow lkysow merged commit ec428f4 into master Mar 6, 2020
@lkysow lkysow deleted the fix-init-race branch March 6, 2020 16:26
Address: a.HTTPAddr,
})
require.NoError(t, err)
s, closer := testConsulSyncer(client)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion:

s, closer := testConsulSyncerWithConfig(client, func(s *ConsulSyncer) {
		s.SyncPeriod = 5 * time.Millisecond
	})

Since the testConsulSyncer also Runs the syncer, the sync period change may not get picked up if it's made afterwards.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. PR coming.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/sync Related to catalog sync type/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants