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

ca: fix a bug that caused a non blocking leaf cert query after a blocking leaf cert query to block #12820

Merged
merged 3 commits into from
Apr 20, 2022

Conversation

rboyer
Copy link
Member

@rboyer rboyer commented Apr 19, 2022

Fixes #12048

Fixes #12319

Regression introduced in #11693

Local reproduction steps:

  1. consul agent -dev
  2. curl -sLiv 'localhost:8500/v1/agent/connect/ca/leaf/web'
  3. make note of the X-Consul-Index header returned
  4. curl -sLi 'localhost:8500/v1/agent/connect/ca/leaf/web?index=<VALUE_FROM_STEP_3>'
  5. Kill the above curl when it hangs with Ctrl-C
  6. Repeat (2) and it should not hang.

@rboyer rboyer requested a review from a team April 19, 2022 15:01
@rboyer rboyer self-assigned this Apr 19, 2022
@github-actions github-actions bot added the theme/agent-cache Agent Cache label Apr 19, 2022
agent/cache/cache.go Outdated Show resolved Hide resolved
Copy link
Contributor

@boxofrad boxofrad left a comment

Choose a reason for hiding this comment

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

Looks great, left a couple of small comments/questions 🎉

agent/agent_endpoint_test.go Outdated Show resolved Hide resolved
agent/agent_endpoint_test.go Show resolved Hide resolved
agent/cache/cache.go Outdated Show resolved Hide resolved
agent/cache/cache.go Outdated Show resolved Hide resolved
…king leaf cert query to block

Fixes #12048
Fixes #12319

Regression introduced in #11693
@rboyer rboyer force-pushed the fix-leaf-cert-blocking-queries branch from 0d1e0cc to 19618c1 Compare April 19, 2022 21:40
@rboyer rboyer changed the title ensure that a leaf cert non-blocking query after a blocking query does not block ca: fix a bug that caused a non blocking leaf cert query after a blocking leaf cert query to block Apr 19, 2022
@@ -376,6 +376,13 @@ func (c *Cache) getEntryLocked(
// Check if re-validate is requested. If so the first time round the
// loop is not a hit but subsequent ones should be treated normally.
if !tEntry.Opts.Refresh && info.MustRevalidate {
if entry.Fetching {
Copy link
Contributor

@acpana acpana Apr 19, 2022

Choose a reason for hiding this comment

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

Ah, this is one of those lines that I hope doesn't surface code that was relying on side effects here.

AFAIK, (and I don't know much) there's not a lot of cache types that actually use MustRevalidate.

So my gut tells me that this should work beautifully for the bug in #12048 🤞🏼

But it would feel good to check in with @banks or @freddygv if they have more context here to get a third/ fourth pair of eyes 💯


ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a non actionable comment:

for any of y'all wondering about testing that the blocking query does what we want for the leaf cert, that use case is here: https://github.com/hashicorp/consul/blob/main/agent/agent_endpoint_test.go#L6016-L6033

@acpana
Copy link
Contributor

acpana commented Apr 19, 2022

hey @rboyer thanks loads for taking this on 🥇 💯 ; that bug has been in the back of my mind 🪨

i see the backport/1.12 tag; I'll leave it up to you if you want to check this in for 1.12 or wait to chat with folks more familiar with the cache layer and have it in 1.12.1. Regardless, I made a milestone tag for 1.12.1 fyi .


// We just need to ensure that the above blocking query is in-flight before
// the next step, so do a little sleep.
time.Sleep(50 * time.Millisecond)
Copy link
Contributor

@kisunji kisunji Apr 20, 2022

Choose a reason for hiding this comment

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

Could we make this deterministic with context.WithTimeout and calling the above code serially?
From a cursory look a cancelled request context should reach the cache machinery before ctx.Done() is ever checked.

I'm fine with merging without; just calling out potential alternatives to sleeping

Copy link
Member Author

Choose a reason for hiding this comment

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

Much like all of the other blocking query tests, the trick is figuring out how to initiate a blocking query that does not return, know it has reached the important part, and only THEN issue your followup query. We don't have any signaling mechanism to know exactly when something is actually blocking.

@rboyer rboyer merged commit f3ce353 into main Apr 20, 2022
@rboyer rboyer deleted the fix-leaf-cert-blocking-queries branch April 20, 2022 17:21
@hc-github-team-consul-core
Copy link
Contributor

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/645590.

@hc-github-team-consul-core
Copy link
Contributor

🍒✅ Cherry pick of commit f3ce353 onto release/1.12.x succeeded!

hc-github-team-consul-core pushed a commit that referenced this pull request Apr 20, 2022
…king leaf cert query to block (#12820)

Fixes #12048

Fixes #12319

Regression introduced in #11693

Local reproduction steps:
1. `consul agent -dev`
2. `curl -sLiv 'localhost:8500/v1/agent/connect/ca/leaf/web'`
3. make note of the `X-Consul-Index` header returned 
4. `curl -sLi 'localhost:8500/v1/agent/connect/ca/leaf/web?index=<VALUE_FROM_STEP_3>'`
5. Kill the above curl when it hangs with Ctrl-C
6. Repeat (2) and it should not hang.
@hc-github-team-consul-core
Copy link
Contributor

🍒✅ Cherry pick of commit f3ce353 onto release/1.11.x succeeded!

@hc-github-team-consul-core
Copy link
Contributor

🍒✅ Cherry pick of commit f3ce353 onto release/1.10.x succeeded!

hc-github-team-consul-core pushed a commit that referenced this pull request Apr 20, 2022
…king leaf cert query to block (#12820)

Fixes #12048

Fixes #12319

Regression introduced in #11693

Local reproduction steps:
1. `consul agent -dev`
2. `curl -sLiv 'localhost:8500/v1/agent/connect/ca/leaf/web'`
3. make note of the `X-Consul-Index` header returned 
4. `curl -sLi 'localhost:8500/v1/agent/connect/ca/leaf/web?index=<VALUE_FROM_STEP_3>'`
5. Kill the above curl when it hangs with Ctrl-C
6. Repeat (2) and it should not hang.
hc-github-team-consul-core pushed a commit that referenced this pull request Apr 20, 2022
…king leaf cert query to block (#12820)

Fixes #12048

Fixes #12319

Regression introduced in #11693

Local reproduction steps:
1. `consul agent -dev`
2. `curl -sLiv 'localhost:8500/v1/agent/connect/ca/leaf/web'`
3. make note of the `X-Consul-Index` header returned 
4. `curl -sLi 'localhost:8500/v1/agent/connect/ca/leaf/web?index=<VALUE_FROM_STEP_3>'`
5. Kill the above curl when it hangs with Ctrl-C
6. Repeat (2) and it should not hang.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants