Skip to content

Conversation

giorio94
Copy link
Member

Currently, the etcd paginatedList implementation is affected by a bug that can lead to missing events of both upsertions and deletions that are performed between the end of the first Get call and the last Get call. Indeed, the tracked revision is incorrectly updated after every Get call, and etcd always returns the current revision, regardless of whether WithRev is actually requesting a specific revision. In turn, this leads to subsequent Get calls targeting different revisions, hence missing all the events happened in between for the already processed chunks of the prefix, as the watch operation is eventually started from the latest retrieved revision.

Let's address this by consistently using the same revision during the entire paginatedList execution, to ensure that we correctly list all entries at that revision, and subsequently start watching events from the next one. Additionally, let's update the associated unit test to additionally cover the parallel operations case and prevent future regressions in this respect.

This bug affected both Cilium running in KVStore mode and clustermesh, although the race condition window is sufficiently short to trigger its occurrence only rarely and in high scale environments.

Marked for backport to all affected versions, as IMO it fits into the

Major bugfixes relevant to the correct operation of Cilium

category, considering the Cilium then only recovers after a restart of the agent (although that may again trigger the same problem).

Fix bug causing etcd upsertion/deletion events to be potentially missed during the initial synchronization, when Cilium operates in KVStore mode, or Cluster Mesh is enabled. 

Currently, the etcd paginatedList implementation is affected by a bug
that can lead to missing events of both upsertions and deletions that
are performed between the end of the first Get call and the last Get
call. Indeed, the tracked revision is incorrectly updated after every
Get call, and etcd always returns the current revision, regardless of
whether WithRev is actually requesting a specific revision. In turn,
this leads to subsequent Get calls targeting different revisions,
hence missing all the events happened in between for the already
processed chunks of the prefix, as the watch operation is eventually
started from the latest retrieved revision.

Let's address this by consistently using the same revision during the
entire paginatedList execution, to ensure that we correctly list all
entries at that revision, and subsequently start watching events from
the next one. Additionally, let's update the associated unit test
to additionally cover the parallel operations case and prevent future
regressions in this respect.

This bug affected both Cilium running in KVStore mode and clustermesh,
although the race condition window is sufficiently short to trigger
its occurrence only rarely and in high scale environments.

Fixes: e33b9f9 ("kvstore: add support for paginated lists in etcd.ListAndWatch")
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
@giorio94 giorio94 added kind/bug This is a bug in the Cilium logic. release-note/bug This PR fixes an issue in a previous release of Cilium. area/clustermesh Relates to multi-cluster routing functionality in Cilium. area/kvstore Impacts the KVStore package interactions. needs-backport/1.14 needs-backport/1.16 This PR / issue needs backporting to the v1.16 branch labels Jul 30, 2024
@giorio94 giorio94 requested a review from a team as a code owner July 30, 2024 13:53
@giorio94
Copy link
Member Author

/test

Copy link
Member

@bimmlerd bimmlerd left a comment

Choose a reason for hiding this comment

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

(not in kvstore) change&tests LGTM, this is definitely a bug.

@bimmlerd
Copy link
Member

bimmlerd commented Aug 2, 2024

@joestringer this is the PR mentioned in the community meeting, maybe you could use your maintainer's priviledges to approve?

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.

I've not generally looked through the etcd logic so I'm catching up a bit on knowledge here but the fix looks good.

@joestringer joestringer merged commit 8b210fb into main Aug 2, 2024
290 of 292 checks passed
@joestringer joestringer deleted the pr/giorio94/main/fix-etcd-paginated-list-bug branch August 2, 2024 16:05
@nbusseneau nbusseneau mentioned this pull request Aug 2, 2024
5 tasks
@nbusseneau nbusseneau added backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. backport/author The backport will be carried out by the author of the PR. needs-backport/1.14 and removed needs-backport/1.14 backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. labels Aug 2, 2024
@nbusseneau
Copy link
Member

nbusseneau commented Aug 3, 2024

The changes in this PR have been introduced after we replaced gocheck with built-in go test in #32261 and are thus a tad annoying to backport as-is to 1.14 and 1.15, which still use gocheck, so I'm marking this as backport/author 😅

@nbusseneau nbusseneau mentioned this pull request Aug 3, 2024
13 tasks
@bimmlerd bimmlerd mentioned this pull request Aug 5, 2024
1 task
@bimmlerd bimmlerd added backport-pending/1.16 The backport for Cilium 1.16.x for this PR is in progress. and removed needs-backport/1.16 This PR / issue needs backporting to the v1.16 branch labels Aug 5, 2024
@bimmlerd bimmlerd mentioned this pull request Aug 5, 2024
1 task
@bimmlerd bimmlerd added backport-pending/1.15 The backport for Cilium 1.15.x for this PR is in progress. and removed needs-backport/1.15 labels Aug 5, 2024
@bimmlerd bimmlerd mentioned this pull request Aug 5, 2024
1 task
@bimmlerd bimmlerd added backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. and removed needs-backport/1.14 labels Aug 5, 2024
@github-actions github-actions bot added backport-done/1.14 The backport for Cilium 1.14.x for this PR is done. backport-done/1.15 The backport for Cilium 1.15.x for this PR is done. backport-done/1.16 The backport for Cilium 1.16.x for this PR is done. and removed backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. backport-pending/1.15 The backport for Cilium 1.15.x for this PR is in progress. backport-pending/1.16 The backport for Cilium 1.16.x for this PR is in progress. labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/clustermesh Relates to multi-cluster routing functionality in Cilium. area/kvstore Impacts the KVStore package interactions. backport/author The backport will be carried out by the author of the PR. backport-done/1.14 The backport for Cilium 1.14.x for this PR is done. backport-done/1.15 The backport for Cilium 1.15.x for this PR is done. backport-done/1.16 The backport for Cilium 1.16.x for this PR is done. 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
Status: Released
Development

Successfully merging this pull request may close these issues.

4 participants