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 race: Make informed watcher start wait for Add event 🏎️ #2036

Merged
merged 2 commits into from
Mar 2, 2021

Conversation

bobcatfish
Copy link
Contributor

Changes

When using the informed watcher to watch a config map, previously add
events were being processed in a goroutine with no syncrhonization
making it so that code may try to access the values backed by the
configmaps before they are initialized.

This commit makes it so that the Start method of the informer will wait
for the add event to occur at least once for all config maps it is
watching.

This commit also undoes the workaround added in #1929 which was working
around the race condition identified in #1907 (and in
tektoncd/pipeline#3720). This means that if
the synchronization was removed, the impacted test would start flaking
again. If we wanted it to reliably fail in that case, we could introduce
a sleep in the callback but that doesn't seem worth it.

I also tested this change by manually patching the changes into my
clone of tektoncd/pipeline and following the repro steps at
tektoncd/pipeline#2815 (comment)
Before the change I can reproduce the issue, and after the change, I
can't! :D

Fixes #1960 🐛

@dprotaso @mattmoor

/kind bug

Release Note

Controllers built using knative/pkg and using the config store watcher for hot reloading of config maps can trust that once the controller has started, the values have been loaded from the backing config maps.

Docs

n/a

@knative-prow-robot knative-prow-robot added the kind/bug Categorizes issue or PR as related to a bug. label Feb 23, 2021
@google-cla google-cla bot added the cla: yes Indicates the PR's author has signed the CLA. label Feb 23, 2021
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 23, 2021
@codecov
Copy link

codecov bot commented Feb 23, 2021

Codecov Report

Merging #2036 (572b926) into master (f4650d8) will increase coverage by 0.31%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2036      +/-   ##
==========================================
+ Coverage   67.05%   67.37%   +0.31%     
==========================================
  Files         213      215       +2     
  Lines        8986     9073      +87     
==========================================
+ Hits         6026     6113      +87     
- Misses       2686     2687       +1     
+ Partials      274      273       -1     
Impacted Files Coverage Δ
configmap/informer/informed_watcher.go 95.12% <100.00%> (+0.91%) ⬆️
configmap/informer/synced_callback.go 100.00% <100.00%> (ø)
metrics/resource_view.go 88.63% <100.00%> (+2.08%) ⬆️
source/source_stats_reporter.go 84.90% <0.00%> (-0.81%) ⬇️
controller/controller.go 85.71% <0.00%> (-0.38%) ⬇️
network/network.go 100.00% <0.00%> (ø)
metrics/metrics_worker.go 71.42% <0.00%> (ø)
test/gcs/mock/mock.go 92.47% <0.00%> (+1.07%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86a8236...572b926. Read the comment docs.

@bobcatfish
Copy link
Contributor Author

I can't tell if the pull-knative-pkg-unit-tests failure is legit 🤔

@bobcatfish
Copy link
Contributor Author

image

image

@bobcatfish
Copy link
Contributor Author

/test pull-knative-pkg-unit-tests

configmap/informer/informed_watcher.go Outdated Show resolved Hide resolved
// Pretend that all the defaulted ConfigMaps were just created. This is done before we start
// the informer to ensure that if a defaulted ConfigMap does exist, then the real value is
// processed after the default one.
i.triggerAddEventForDefaultedConfigMaps(addConfigMapEvent)
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 WaitForAllKeys won't actually wait for config map updates from the API server since processing the default configmaps here lowers the wait group count to 0. I'm assuming that's expected just confirming.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, that's the case but only when using defaulted config maps - i wasnt totally clear on the expectations when using defaulted them, does this match what you think it should do? (i can add some comments at least explaining this if you can confirm this is what we want)

it DOES wait when you're not using defaulted config maps (e.g. in tekton pipelines afaik we're not using defaulted configmaps: https://github.com/tektoncd/pipeline/blob/93e368dbcb014e8650a6ba8ad01ca3c5f6eb6554/vendor/knative.dev/pkg/configmap/store.go#L114)

Copy link
Member

Choose a reason for hiding this comment

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

I'm good with what you described - ie. if you include defaulted config maps then we don't wait for a sync from the API

Can you add the comment to both Start & WatchWithDefault ?

configmap/informer/informed_watcher.go Show resolved Hide resolved
@dprotaso
Copy link
Member

Thanks for the PR! Yeah metrics tests are flakey

@bobcatfish
Copy link
Contributor Author

should be ready for another look @dprotaso !

@dprotaso
Copy link
Member

/retest

When using the informed watcher to watch a config map, previously add
events were being processed in a goroutine with no syncrhonization
making it so that code may try to access the values backed by the
configmaps before they are initialized.

This commit makes it so that the Start method of the informer will wait
for the add event to occur at least once for all config maps it is
watching.

This commit also undoes the workaround added in knative#1929 which was working
around the race condition identified in knative#1907 (and in
tektoncd/pipeline#3720). This means that if
the synchronization was removed, the impacted test would start flaking
again. If we wanted it to reliably fail in that case, we could introduce
a sleep in the callback but that doesn't seem worth it.

I also tested this change by manually patching the changes into my
clone of tektoncd/pipeline and following the repro steps at
tektoncd/pipeline#2815 (comment)
Before the change I can reproduce the issue, and after the change, I
can't! :D

Fixes knative#1960
These utility objects don't really make sense to expose as part of the
informed watcher package and are only used by the informed watcher.
Writing tests for unexported code makes me a bit :( but hopefully these
will get moved to some other package one day. And there's really no
reason to expose these to users of knative/pkg at the moment.
@bobcatfish
Copy link
Contributor Author

@dprotaso I've updated the comments, lemme know what you think!

Copy link
Member

@dprotaso dprotaso left a comment

Choose a reason for hiding this comment

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

thanks for the changes!

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 2, 2021
@dprotaso
Copy link
Member

dprotaso commented Mar 2, 2021

/approve
/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 2, 2021
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot merged commit 2bc944b into knative:master Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race condition when using config store backed by config maps
3 participants