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 Unlock handling for kvstore locks #9973

Merged
merged 2 commits into from
Jan 28, 2020
Merged

Conversation

aanm
Copy link
Member

@aanm aanm commented Jan 27, 2020

This PR fixes a couple bugs encountered in master with regarding the handling of unlock function. Please read per commit for more info.

Does not f i x: #9855


This change is Reviewable

@aanm aanm added kind/bug This is a bug in the Cilium logic. pending-review release-note/bug This PR fixes an issue in a previous release of Cilium. labels Jan 27, 2020
@aanm aanm requested review from a team as code owners January 27, 2020 15:03
@maintainer-s-little-helper maintainer-s-little-helper bot added this to In progress in 1.7.0 Jan 27, 2020
@aanm
Copy link
Member Author

aanm commented Jan 27, 2020

test-me-please

@coveralls
Copy link

coveralls commented Jan 27, 2020

Coverage Status

Coverage increased (+0.03%) to 45.987% when pulling 1c2a453 on pr/fix-kvstore-lock-master into 99ce38b on master.

Copy link
Member

@tgraf tgraf left a comment

Choose a reason for hiding this comment

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

Only a minor nit but I think it's important to track context TODOs correctly.

@@ -443,7 +443,7 @@ func (a *Allocator) lockedAllocate(ctx context.Context, key AllocatorKey) (idpoo
return 0, false, err
}

defer lock.Unlock(ctx)
defer lock.Unlock(context.TODO())
Copy link
Member

Choose a reason for hiding this comment

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

I think we want Background() as this is not a context that has yet to be defined but it's a context that should never expire.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah that's a good point. Fixed

@aanm aanm force-pushed the pr/fix-kvstore-lock-master branch from ee53547 to 886a28c Compare January 27, 2020 21:35
@aanm
Copy link
Member Author

aanm commented Jan 27, 2020

test-me-please

@aanm aanm requested a review from tgraf January 27, 2020 21:35
@joestringer
Copy link
Member

test-me-please

Copy link
Member

@joestringer joestringer left a comment

Choose a reason for hiding this comment

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

Yikes.

Using the same context used to lock a key is not the right functionality
that we want as it can cause distributed locking issues. For example, in
case a client gets a distributed key and the context is canceled while
that lock is being held, the Unlock() functions will not execute since
that same context was canceled leaving the distributed lock locked until
the client disconnects from the kvstore.

Fixes: d3ad5c7 ("kvstore: plumb context")
Fixes: 157089d ("allocator: add context to `RunGC`")
Signed-off-by: André Martins <andre@cilium.io>
Earlier returning from the function stating the lock was acquired it
might make the caller of waitForInitLock to cancel the context to
earlier which makes the Unlock operation to fail. Althought this context
bug was fixed by "pkg/kvstore: use different context for lock and unlock"
the right behavior of this function should be to return successfully
after the Unlock was performed.

Signed-off-by: André Martins <andre@cilium.io>
@aanm aanm force-pushed the pr/fix-kvstore-lock-master branch from 886a28c to 1c2a453 Compare January 28, 2020 09:38
@aanm
Copy link
Member Author

aanm commented Jan 28, 2020

test-me-please

@aanm aanm merged commit 8e0b5f2 into master Jan 28, 2020
1.7.0 automation moved this from In progress to Merged Jan 28, 2020
@aanm aanm deleted the pr/fix-kvstore-lock-master branch January 28, 2020 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug This is a bug in the Cilium logic. release-note/bug This PR fixes an issue in a previous release of Cilium.
Projects
No open projects
1.7.0
  
Merged
Development

Successfully merging this pull request may close these issues.

None yet

4 participants