Freezing forge app

Hi there,

I am trying to do:

  1. pull 50 rows from third party API
  2. create payloads for issues
  3. create issues (bulk)
  4. back to step 1. until I pulled all rows from third party API.

Code:

/**
 * Create Jira Issues
 *
 * @param configuration
 * @param assetType
 * @param allIds
 * @param findingsOffset
 */
export const createJiraIssue = async (configuration: IntegrationConfiguration, assetType: string, allIds: any, findingsOffset: number) => {

//HERE I AM GETTING 50 rows from third party API
    const findings: any = await getAllFindings(configuration.assets, 'open', assetType, findingsOffset);
    const custom_field: string = await storage.get('whvid_custom_field_id');
    let jiraIssuePayloads : any = {"issueUpdates": []};

    for (const item of findings.collection) {
        const i = findings.collection.indexOf(item);

        //Check if we can create the Jira issue
        if (!allIds.includes(item.id.toString()) && await isVulnerabilityAllowedToCreate(item)) {
//create payloads for issues
}

            
    //CREATE issues bulk
     await createIssues(jiraIssuePayloads);
 
    jiraIssuePayloads = null;
  //here I am calling same function but with new offset
    if (findings['offset'] > 0) {
        await createJiraIssue(configuration, assetType, allIds, findings['offset']);
    }
}

Third party API call:

export const getAllFindings = async (assets: [], status: string, assetType: string, startOffset: number) => {

    const findings =  await getFindingByAssetIdAndAssetType(assets, status, assetType, startOffset.toString());

    if(findings.page.totalPage !== findings.page.currentPage){
        findings.offset = startOffset + limit.FINDINGS;
    }

    return findings;

}

My app usually stop working after 18th call. With no error no logs anything. I am very new to JS, so maybe problem is async functions.
Any idea what can be problem?

Thank you

hi @janambroz,

Thanks for posting to Developer Community.

How log does’t your app run function for while in the loop? There’s a 25 second timelimit

As well as 100 requests to Confluence or Jira.

Are you hitting these limits?

Regards,
James.

hi @jrichards ,

so that mean functions in backend can run max 25 seconds? Probably I am running it probably longer. Is there a way to stop function and run it again for another 25 seconds?
In my for loop I am processing 100 elements on every call.

I do less than 100 requests.

If I reach some of this limits will I get some error message?

Thank you
Jan

Hi @janambroz,

I’m not sure about re-running a stopped process. Is there some way you can run multiple tasks in parallel to grab the external 50 and create the Jira issues?

Are you running locally with forge tunnel and not seeing logs? Is there nothing in Developer Console?

James.

I am pulling 50 and then send it to loop to create issues payload and then bulk create issues.
I am not using “await” for any of this process. But after 5000 elements tunnel/app freeze and I can not reload app and can not see any error message in tunnel.

Tunnel logs:

INFO    15:58:20.094  6a4ab9feb75fe3cc  8/4/2022, 3:58:20 PM INFO ---------------------INTEGRATION STARTED----------------------------
INFO    15:58:20.429  6a4ab9feb75fe3cc  8/4/2022, 3:58:20 PM INFO ---------------------SAST SYNC STARTED----------------------------
INFO    15:58:21.010  6a4ab9feb75fe3cc  8/4/2022, 3:58:21 PM INFO ---------------------STARTING CREATING JIRA ISSUES----------------------------
INFO    15:58:51.607  6a4ab9feb75fe3cc  OFFSET: 0
INFO    15:58:59.660  6a4ab9feb75fe3cc  OFFSET: 500
INFO    15:59:07.618  6a4ab9feb75fe3cc  OFFSET: 1000
INFO    15:59:15.082  6a4ab9feb75fe3cc  OFFSET: 1500
INFO    15:59:22.493  6a4ab9feb75fe3cc  OFFSET: 2000
INFO    15:59:30.248  6a4ab9feb75fe3cc  OFFSET: 2500
INFO    15:59:37.818  6a4ab9feb75fe3cc  OFFSET: 3000
INFO    15:59:45.645  6a4ab9feb75fe3cc  OFFSET: 3500
INFO    15:59:53.436  6a4ab9feb75fe3cc  OFFSET: 4000
INFO    16:00:01.146  6a4ab9feb75fe3cc  OFFSET: 4500
INFO    16:00:09.156  6a4ab9feb75fe3cc  OFFSET: 5000

you can see that in ~2 minutes app stop responding.

Hi @janambroz,

I don’t have a specific answer, but it really does look like you’re hitting the limits I mentioned earlier. As Forge is lambda based, it’s more designed to handle small, quick code paths rather than something like this.

Regards,
James.