-
Notifications
You must be signed in to change notification settings - Fork 204
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
Async Update Polling #1088
Async Update Polling #1088
Conversation
internal/internal_workflow_client.go
Outdated
WaitPolicy: &wait, | ||
Identity: w.client.identity, | ||
} | ||
resp, err := w.client.workflowService.PollWorkflowExecutionUpdate(grpcCtx, &pollReq) |
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 needs to be in a loop and the server needs to wait no longer than 60s before sending back a "not yet, try again". This helps with our philosophy of promising to proxy creators and others that we have no call lasting longer than like 80s (we time out poll calls on our side after 70s, which we should do here probably too IMO).
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.
Forgot about this aspect so overall I agree.
Curious about the specific timeout values though - the server's default long-poll timeout cap is 3 minutes so I assume the 60s limit comes from the client side?
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.
the server's default long-poll timeout cap is 3 minutes
Right, but what I believe the server does on task poll is to preempt that with an empty return after 60 or 70s IIRC. We also want to do that here. We don't want timeout to be reached, we want a successful-yet-empty-meaning-try-again response.
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.
Server is just going to return a GRPC timeout status here, it won't (and IMO shouldn't) do the early-return trick. But I can detect that and retry if the parent context still has some life left in it.
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.
I think we should do the early return "trick". I don't think it's a failing state to have a poll say "nothing yet" after a period of time. This is different than a timeout which the caller cannot differentiate between a real timeout (client or server side based on context deadline) and this one.
Whatever we choose to do, I think it needs to never take longer than a worker poll. And I believe we are telling people with proxies to set their max RPC timeouts at 80s. And the client should retry forever (or as long as their caller is willing) in the scenario where it isn't done yet. I think when you write the if statement to have the client retry on gRPC code timeout, it'll become clear that reusing timeout here is not the best.
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.
Fixed up to loop until the parent context .Err() returns non-nil. The server is definitely returning a GRPC timeout status right now (and that was an intentional design choice) but I can verify that we're happy with the approach again.
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.
What error status does the server return here DEADLINE_EXCEEDED
?
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.
Yes. Well, and some other stuff too, like NOT_FOUND for workflow-not-found. But I assume you're asking in the context of timeouts
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.
Yes, I am basically trying to make sure these expected timeouts won't count against our SLAs
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.
Yep, confirmed with the server team who requested this style in the first place.
|
||
if uh.err != nil || valuePtr == nil { | ||
return uh.err | ||
func (luh *lazyUpdateHandle) Get(ctx context.Context, valuePtr interface{}) error { |
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.
I remember discussions around being able to wait for a stage instead of completion, is that a future PR? Also, is there any way for me to just check whether completed in a non-poll/non-blocking way?
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.
That would be subsequent to this, yes. This is just enough to get e2e working being async and blocking on ACCEPTED.
As for checking Ready() (or similar) - by "non-blocking" would you be OK with a (short-ish) RPC? Because that would be necessary with the current impl (i.e. no Future to check)
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.
Spoke w/Chad - we both see TryGet as a likely near-term request. Less clear is some form of "describe" API to observe execution state. We can wait for some usecases for the latter.
client/client.go
Outdated
// WorkflowUpdateRef reflects the fields needed to refer to a workflow | ||
// update. | ||
// NOTE: Experimental |
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.
Probably worth explaining why/how this is distinguished from a handle
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.
Ended up getting rid of this interface in favor of a struct which is only a struct for future extensibility purposes.
internal/internal_workflow_client.go
Outdated
WaitPolicy: &wait, | ||
Identity: w.client.identity, | ||
} | ||
resp, err := w.client.workflowService.PollWorkflowExecutionUpdate(grpcCtx, &pollReq) |
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.
I would say since the retrying is hidden from the user, whether or not the early-return thing is used isn't relevant except to make it easy for us to detect and retry (and possibly the proxy thing, but I don't know if we actually advise users that).
The early return does feel slightly lame, though I can't really pinpoint exactly why. And actual timeout feels more semantically appropriate to me, and we can distinguish which one is which by including a bit of metadata.
As much as it's not my favorite argument, I can kinda get sticking with the early return to keep things consistent w/ other long pollers
@@ -63,6 +66,8 @@ const ( | |||
defaultGetHistoryTimeout = 65 * time.Second | |||
|
|||
getSystemInfoTimeout = 5 * time.Second | |||
|
|||
pollUpdateTimeout = 60 * time.Second |
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.
For other polls, we make sure the server returns 10 seconds before this I believe. Can you confirm that will happen here?
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.
As it stands, that will not happen. Server prefers to return DeadlineExceeded here.
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.
Server prefers to return DeadlineExceeded here.
I don't think that's true on normal long polls. I think it returns an empty success and I think it should here. Helps with error code tracking and such. I don't think it's an error case for your update to not be done yet.
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.
I don't think that's true on normal long polls
This is correct. It was an intentional decision to use DEADLINE_EXCEEDED here and understood to be different than the queue polling calls.
internal/internal_workflow_client.go
Outdated
) | ||
resp, err := w.client.workflowService.PollWorkflowExecutionUpdate(ctx, &pollReq) | ||
cancel() | ||
if err == context.DeadlineExceeded || status.Code(err) == codes.DeadlineExceeded { |
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.
How do you know this isn't a legitimate deadline-exceeded from the server? Or how do you know this isn't a user-defined context deadline that we should bubble out? I think we need an empty response from the server here before SDK timeout. We don't need error codes appearing on normal operation. SDK side timeout IMO should only occur on actual error.
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.
I think I'm missing your intent here ... all DeadlineExceededs from the server are legitimate?
If it's the parent context that failed, we won't loop through again (see guard on for loop) - I added a test for the same.
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.
all DeadlineExceededs from the server are legitimate?
Is there not way to tell the difference between the server not responding and the update not being complete yet?
Saw the discussion above
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.
If you're fetching the result of an update, I don't think there exists a meaningful difference.
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.
SDK side timeout IMO should only occur on actual error.
Is your suggestion then that when the caller-supplied context ends (timeout, cancel, whatever) and the outcome is not yet available then Handle.Get(ctx, valuePtr) should not return an error and also should not set the valuePtr?
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.
(a) can we run the this-code-will-not-respect-the-passed-context argument to ground before shifting? I really don't see in the code where that's the case and am asking you to make that clear
(b) re: the failure metric - I have no idea and will look into it. But again, the server's intention is to use a DEADLINE_EXCEEDED here so we may need to make allowances like we've done with longPoll.
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.
can we run the this-code-will-not-respect-the-passed-context argument to ground before shifting?
I think your context check in the loop is enough. So we can shift now. User context is no longer a concern. It just popped in my head as the first of many concerns about reusing errors for flow here.
But again, the server's intention is to use a DEADLINE_EXCEEDED here so we may need to make allowances like we've done with longPoll.
Can we also run the "server's intention" argument into the ground before shifting? Why is that the intention? Why can that not change? Do they do that on other long polls?
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.
It can absolutely change but you're talking about something that was discussed and settled a few weeks ago so it's not the sort of thing that's going to happen in the context of this PR.
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.
👍 I vote for changing it. If it can't change now, ok, but I think it should. I think we'll be happier for it. In the meantime, the error-based control flow is probably ok enough. My fear is if we don't change soon we never will.
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.
If it helps, the code change to treat a nil response.Outcome as a signal to retry (subject to the parent context, natch) means that we can change the server without breaking field SDKs.
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.
Approving with the known caveat that we will change server to not use error codes to signify update not completed yet
The codegen referenced here has been removed from this repository.
This consists mainly of exposing the WaitPolicy to users of the workflow client and implementing a lazy version of WorkflowUpdateHandle.
Loop inside the PollWorkflowClient stub function calling up to the server with a context built from the long poll timeout.
Also refactors tests to use an init() func since gomock attaches its validation to t.Cleanup() so it's wrong to re-use gomock controller instances across sub-tests.
Will now retry in 3 cases: 1. local context deadline exceeded 2. grpc error with DEADLINE_EXCEEDED 3. No error but grpc response does not contain an outcome
What was changed
Adds support for async updates
Why?
Planned feature
Checklist
Closes
How was this tested:
Unit tests here and a succeeding feature test that is waiting on this PR and an server PR