# Activity completes long after ScheduleToCloseTimeout

**URL:** <https://community.temporal.io/t/activity-completes-long-after-scheduletoclosetimeout/10298>\
**Category:** Community Support\
**Tags:** go-sdk, retries\
**Created:** [December 5, 2023, 8:28pm UTC](https://community.temporal.io/t/activity-completes-long-after-scheduletoclosetimeout/10298 "2023-12-05T20:28:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![julienkb](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@julienkb](https://community.temporal.io/u/julienkb)\
**Post date:** [December 5, 2023, 8:28pm UTC](https://community.temporal.io/t/activity-completes-long-after-scheduletoclosetimeout/10298/1 "2023-12-05T20:28:00Z")

</div>

Hi Temporal experts,

We have a temporal activity that we use to poll whether some action has occurred by a certain time. The activity returns an error if the action hasn’t occurred, and uses the following activity options and retry policy, based loosely on [this recommendation](https://community.temporal.io/t/what-is-the-best-practice-for-a-polling-activity/328/2):

```auto
temporal_workflow.ActivityOptions{
	ScheduleToCloseTimeout: durationUntilWakeTime,
	RetryPolicy: &temporal.RetryPolicy{
		InitialInterval: 30 * time.Second,
		BackoffCoefficient: 1.0,
		MaximumAttempts: 1000,
	},
},

```

Usually, this activity works as intended. However, today we encountered an issue where the activity finished way after the expected deadline; specifically, we scheduled the activity at 13:57 UTC and set the `ScheduleToCloseTimeout` to 1h29m, so we were expecting the activity to complete by 15:26 UTC. Instead, the activity actually completed (with a ScheduleToClose timeout error) at 16:56 UTC. Attached a screenshot of the temporal UI below.

Our logs show that the activity started running at 13:57 UTC, and the last retry occurred at 15:26 UTC, so we’re wondering why the activity failed at 16:56 UTC instead of at 15:26 UTC? We’re not sure if this is related, but the Temporal UI shows the “ActivityTaskStarted” at 15:26 UTC, and the time out occurred 1h29m after that “ActivityTaskStarted” (which matches the `ScheduleToClose` duration).

 ![Screenshot 2023-12-05 at 1.48.04 PM](https://us1.discourse-cdn.com/flex016/uploads/temporal/original/2X/b/b0b918f398712b53c3c12ec9281b7f86067432b4.png)

Any help understanding the issue would be much appreciated! Thanks!

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [December 5, 2023, 10:09pm UTC](https://community.temporal.io/t/activity-completes-long-after-scheduletoclosetimeout/10298/2 "2023-12-05T22:09:19Z")

</div>

Hi could you share the full event history json of this execution please? Do you have service metrics configured that we could look at? Also which server version are you using?

Just in general, it’s recommended to always set activity StartToClose timeout. Use ScheduleToClose to restrict retries via time, or if need to restrict retries via number of attempts use RetryPolicy-\> MaximumAttempts, so no need to use both i think.

(also just in case, this does look possibly like a bug so knowing server version and your sdk version as well as if there is a way to repro this would help)

---

<div class="post-metadata">

**Author:** ![julienkb](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@julienkb](https://community.temporal.io/u/julienkb)\
**Post date:** [December 5, 2023, 11:15pm UTC](https://community.temporal.io/t/activity-completes-long-after-scheduletoclosetimeout/10298/3 "2023-12-05T23:15:39Z")

</div>

Hi, we’re using v1.25.1 of the golang SDK and Temporal cloud. I’ll also send you the JSON via Slack or email (this page doesn’t seem to allow me to upload raw JSON).

And good to know about also setting the activity StartToClose timeout - I’ll give that a try!

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [December 6, 2023, 12:30am UTC](https://community.temporal.io/t/activity-completes-long-after-scheduletoclosetimeout/10298/4 "2023-12-06T00:30:16Z")

</div>

Thanks, please always set StartToClose timeout on your activities.  
We will have more info on ticket but for now if last activity attempt (retry) happens right before ScheduleToClose time it can happen that ScheduleToClose gets extended. This is something team will fix in the future.  
Setting a smaller and appropriate StartToClose timeout for activity is always recommended to do and in your case would fail the activity a lot sooner.

Another thing to look into is whats going on with the activity? if you have sdk metrics enabled look at  
`activity_execution_latency` as well as `request_latency` metric for operation RespondActivityTaskCompleted please.

---

<div class="post-metadata">

**Author:** ![Ljube](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/ljube/32/5624_2.png) [@Ljube](https://community.temporal.io/u/Ljube)\
**Post date:** [July 25, 2024, 12:08pm UTC](https://community.temporal.io/t/activity-completes-long-after-scheduletoclosetimeout/10298/5 "2024-07-25T12:08:00Z")

</div>

Hello @tihomir,

Did you already get a chance to open up a ticket for this - was there any progress on making it work only with the `ScheduleToCloseTimeout`? I’m reviving this topic in the hope of simplifying the activity options in our system.

Thanks in advance!
