-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Conversation
There was a problem hiding this 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 🎉
0d1e0cc
to
19618c1
Compare
@@ -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 { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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
hey @rboyer thanks loads for taking this on 🥇 💯 ; that bug has been in the back of my mind 🪨 i see the |
|
||
// 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
🍒 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. |
🍒✅ Cherry pick of commit f3ce353 onto |
…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.
🍒✅ Cherry pick of commit f3ce353 onto |
🍒✅ Cherry pick of commit f3ce353 onto |
…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.
…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.
Fixes #12048
Fixes #12319
Regression introduced in #11693
Local reproduction steps:
consul agent -dev
curl -sLiv 'localhost:8500/v1/agent/connect/ca/leaf/web'
X-Consul-Index
header returnedcurl -sLi 'localhost:8500/v1/agent/connect/ca/leaf/web?index=<VALUE_FROM_STEP_3>'