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 LA start to close timeout #1180

Merged

Conversation

Quinn-With-Two-Ns
Copy link
Contributor

This PR fixes a few issues with local activities in Got

  • ScheduleToCloseTimeout was overriding StartToCloseTimeout if both were set
  • The docs in LocalActivityOptions were not accurate
  • If a local activity did timeout it would always be considered a SCHEDULE_TO_CLOSE timeout and that is not retry able
  • ActivityInfo in local activities was missing some fields

scheduleToCloseTimeout = startToCloseTimeout
}
deadline := calculateActivityDeadline(task.scheduledTime, startedTime, scheduleToCloseTimeout, startToCloseTimeout)
if task.attempt > 1 && !task.expireTime.IsZero() && task.expireTime.Before(deadline) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is still an open issue if we should removed this/can remove this. This expireTime is calculated based on the ScheduleToCloseTimeout and the workflow time, but is only used on the second attempt. This has been basically unchanged for 4+ years, but seems wrong.

Copy link
Member

Choose a reason for hiding this comment

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

While wrong, let's leave for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I agree, just wanted to call this out since when we put Go on Core this will be something we have to deal with.

@Quinn-With-Two-Ns Quinn-With-Two-Ns marked this pull request as ready for review July 28, 2023 17:03
@Quinn-With-Two-Ns Quinn-With-Two-Ns requested a review from a team as a code owner July 28, 2023 17:03
internal/activity.go Outdated Show resolved Hide resolved
internal/activity.go Outdated Show resolved Hide resolved
internal/activity.go Outdated Show resolved Hide resolved
internal/internal_event_handlers.go Outdated Show resolved Hide resolved
Comment on lines -567 to -590
timeout := task.params.ScheduleToCloseTimeout
if task.params.StartToCloseTimeout != 0 && task.params.StartToCloseTimeout < timeout {
timeout = task.params.StartToCloseTimeout
}
timeoutDuration := timeout
deadline := time.Now().Add(timeoutDuration)
if task.attempt > 1 && !task.expireTime.IsZero() && task.expireTime.Before(deadline) {
// this is attempt and expire time is before SCHEDULE_TO_CLOSE timeout
deadline = task.expireTime
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't see anything obvious, but are there any ways that you can think of that this logic has changed with your new logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only change here is using the scheduled time + ScheduleToCloseTimeout when calculating the deadline (used to be time.Now). It probably won't effect many activities because for the first attempt scheduled time will be close to time.Now and subsequent attempts task.expireTime uses workflow time so it will always be shorter than either deadline

Copy link
Member

@cretz cretz Jul 31, 2023

Choose a reason for hiding this comment

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

So if today I have a schedule to close timeout of 5s, my second attempt would get the full 5s (even though that's improper)? But after this change, it will only get however much time remains the beginning of the first attempt? Sorry I didn't dig into how expireTime is set. If this is the case, I may hit you up off-PR to communicate with one or two known heavy local activity users to confirm this is acceptable.

Copy link
Contributor Author

@Quinn-With-Two-Ns Quinn-With-Two-Ns Jul 31, 2023

Choose a reason for hiding this comment

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

So if today I have a schedule to close timeout of 5s, my second attempt

Today you would have no second attempt because schedule to close is not retried

Copy link
Member

Choose a reason for hiding this comment

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

Confirmed off-PR that second-attempt after first-attempt-immediate-failure is bounded today by expireTime regardless.

@@ -644,7 +635,11 @@ WaitResult:
metricsHandler.Counter(metrics.LocalActivityExecutionCanceledCounter).Inc(1)
return &localActivityResult{err: ErrCanceled, task: task}
} else if ctx.Err() == context.DeadlineExceeded {
return &localActivityResult{err: ErrDeadlineExceeded, task: task}
if task.params.ScheduleToCloseTimeout != 0 && time.Now().After(info.scheduledTime.Add(task.params.ScheduleToCloseTimeout)) {
Copy link
Member

Choose a reason for hiding this comment

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

I wish there was a better way to know which timeout was hit instead of having to do math here.

@@ -156,11 +156,13 @@ type (
// LocalActivityOptions stores local activity specific parameters that will be stored inside of a context.
LocalActivityOptions struct {
// ScheduleToCloseTimeout - The end to end timeout for the local activity including retries.
// This field is required.
// At least on of ScheduleToCloseTimeout or StartToCloseTimeout is required.
// defaults to StartToCloseTimeout if not set.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default for ScheduleToCloseTimeout for normal activities is infinity. We could be consistent here, but that might be a breaking change.

@Quinn-With-Two-Ns Quinn-With-Two-Ns merged commit 1ec43ad into temporalio:master Aug 2, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants