Behavior of the 20 sec. timeout in scheduled event handler

We are currently developing a Freshworks app for a data sync use case. We are planning to use the Scheduled Events feature of the serverless app. During our analysis, we found the 20 sec. timeout limitation. Below are our findings related to this limitation.

When we use a long-running operation without calling an API or before calling an API using axios or request method:

scheduledEventHandler: async function(payload) {
    try{ 
      for(let n = 0; n < 10000000; n++){
        console.log("test ==>", n);
      }
      await axios.get("https://stale-jokes-design-103-108-207-58.loca.lt");
    } catch(err){
      console.log("err ==>", err);
    }
}

After 20 sec., it results in:

Error: Script execution timed out after 20000ms
    at Script.runInContext (vm.js:144:12)
    at AppEvent.sandboxExecutor

...
...

But if we call API using axios or request method before a long-running operation:

scheduledEventHandler: async function(payload) {
    try{ 
      await axios.get("https://stale-jokes-design-103-108-207-58.loca.lt");
      for(let n = 0; n < 10000000; n++){
        console.log("test ==>", n);
      }
    } catch(err){
      console.log("err ==>", err);
    }
}

We did not face the 20 sec timeout error in the above case.

Question 1: What exact operations can cause the 20 sec. timeout error, as per the above example, this limitation is a bit ambiguous.

Question 2: In the later case (call API using axios or request method before a long-running operation), we ran it for about 20 mins and we didn’t encounter the timeout error. What will be the max. timeout of the handler in this case.

@kaustavdm @Raviraj Can you add your inputs on the above questions if possible?

@Sagar_Gujarati

There are a few more things I would like to learn about the analysis

  1. Did you run both of these situations in production (as a custom app) or only in a local simulation?
  2. In case #1, Is the Script execution timed out invoked as part of the catch(){..} block? I mean, do you see err ==> in the log?

Before I could answer you question,

Do you mind analyzing #2 as follows and let us know what you learn?

scheduledEventHandler: async function(payload) {
    try{ 
      await axios.get("https://stale-jokes-design-103-108-207-58.loca.lt");
    } catch(err){
      console.log("err ==>", err);
    }
     for(let n = 0; n < 10000000; n++){
        console.log("test ==>", n);
      }
}

Important points from the meeting of developer relations:

As discussed in the meeting, please find the questions/concerns below:

Question 1:

  1. We are interested in the CMDB related usecase of Freshservice. For that, we need to sync the assets from Lansweeper to Freshservice CMDB. Now, this would be a long and costly process which comprises of the following steps at high level:

    1. Fetch the assets from Lansweeper.
    2. Fetch the field mapping (Freshservice API) of the supported Asset Types.
    3. Fetch the details of the dropdown fields (like the product, vendor, etc) from the Freshservice.
    4. Carry out the transformation of assets one by one.
    5. Create a new asset or update the asset if it already exists.
  2. We are planning to use the callback of the scheduler to carry out this syncing process. However, as per the documentation, this callback can only execute for 20 seconds. All the mentioned processes are not possible in a mere 20 s time. As a result, we are facing an issue.

  3. One of the possible solutions is using middleware. But as it includes handling of the extra servers from the client side, we want to avoid it.

Question 2:

  1. We are planning to use Oauth for authentication. However, Lansweeper returns code 400 in case access_token is expired. It seems that Freshservice is expecting status code 401 and because of that the access_token is not getting refreshed. Is there any way to solve this issue?
  2. Is there a way we can access different params of OAuth within the code?

CC: @Saif @kaustavdm

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.