Handling function timeouts in Atlassian Forge - Any solutions?

Hi everyone,

I hope you all are doing well. I’ve encountered an issue with Atlassian Forge that I hope someone here may have encountered before and can provide some advice.

As we all know, Forge functions have a hard limit of 25 seconds for their execution time. While this might not be an issue for smaller tasks, for more compute-intensive ones, like calling AI systems that require a bit of time to respond, this limit can be a hindrance.

Often, the function times out and users are presented with the less-than-user-friendly error message, “Function timed out past limit of 25.03 seconds”.
image
Needless to say, this doesn’t provide the best user experience and leaves our users in the dark about what exactly went wrong and what they can do about it.

I’ve been looking for ways to catch this timeout error within the Forge function, so I can handle it more gracefully. However, so far I have been unable to do so and my search in the Forge documentation has not yielded any positive results. It seems that these timeouts can’t be caught and handled programmatically.

So, I’m reaching out to the community to verify this.

  1. Is it true that function timeouts in Forge can’t be caught or handled?
  2. If yes, how are you all dealing with this? Are there any best practices or workarounds that you’d recommend for handling these timeouts more gracefully?
  3. If timeouts can be caught, could you share some code snippets or point me towards the right resources where I can learn to implement this?

This is a critical issue for us, and I’m sure many other developers using AI systems or other time-consuming tasks in their Forge apps face similar challenges.

Any advice or insights would be greatly appreciated!

Thanks in advance for your help.

Best regards,

Rick

2 Likes

You can’t fix the time out error. Best thing would to have an external system where you post the request to - and get a token back that you can track. Then after that you can poll to see if the request has finished. (welcome to the good old days of web development).

@rick.van.twillert,

  1. Is it true that function timeouts in Forge can’t be caught or handled?

I confirm they are not available to your code as exceptions. You would see INVOCATION_FAILED in logs.

  1. If yes, how are you all dealing with this? Are there any best practices or workarounds that you’d recommend for handling these timeouts more gracefully?

From my experience, most apps aren’t running into the timeouts. But, there does seem to be a special case of “long calls” for AI. ChatGPT and friends often timeout.

  1. If timeouts can be caught, could you share some code snippets or point me towards the right resources where I can learn to implement this?

I think you can use Node’s setTimeout to help guard against long calls. I’m pretty sure the following will work in any Forge invocation context (not just Forge UI):

Thanks all! Will look into this!