Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

clock: protect field access with lock to avoid possible data race #3984

Open
yanke-xu opened this issue Mar 6, 2023 · 1 comment
Open

clock: protect field access with lock to avoid possible data race #3984

yanke-xu opened this issue Mar 6, 2023 · 1 comment

Comments

@yanke-xu
Copy link

yanke-xu commented Mar 6, 2023

Fixed inconsistency and also potential data race in weave/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go:
f.waiter is read/written 4 times in weave/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go; 3 out of 4 times it is protected by f.fakeClock.lock/f,lock; 1 out of 4 times it is read without a Lock, which is in func C on L317.
A data race may happen when C() and other func like Stop() are called in parallel.

In order to avoid potential data race here, I use f.fakeClock.lock.RLock(); defer f.fakeClock.lock.RUnlock() to make sure that all usages of items is in critical section.

@yanke-xu
Copy link
Author

I don't know whether it is accurate, so I 'm looking forward to your reply.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant