Frequent 'Socket Hang Up' Errors with fetch() and api.asApp().requestJira() in Forge App

Hi guys,

I’ve recently been encountering frequent errors in my Forge app when using fetch() and api.asApp().requestJira(). The error message reads: “reason: socket hang up at ClientRequest.” However, the same code rarely caused issues in the past. Has anyone else experienced this? Any insights or solutions would be greatly appreciated!

My codes like these:

const ret = await api.asApp().requestJira(route`/rest/api/3/issue/12345?fields=summary,reporter,project,worklog`, {
        headers: {
            'Accept': 'application/json'
        }
    });
const response = await fetch('https://my.domain/my/action/', {
        method: 'POST',
        headers: {
            'Authorization': 'Bearer <my token>',
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(data)
    });

Hi @FengLu ,
Could you please provide details of a reproducible example app for this?
Please feel free to create a support ticket if necessary

Hi @LashaniPerera,

I am encountering the same error when using Fetch() and api.asApp().requestJira() methods.
When i checked my developer logs its shows like :

Error fetching paginated projects for the query:
FetchError: request to https://domain.atlassian.net/rest/api/3/project/search?query=&startAt=0&maxResults=50 failed, reason: socket hang up
    at ClientRequest.<anonymous> (webpack://jira-issue-panel-custom-ui/node_modules/@forge/api/node_modules/node-fetch/lib/index.mjs:1495:1)
    at ClientRequest.emit (node:events:529:35)
    at TLSSocket.socketCloseListener (node:_http_client:474:11)
    at TLSSocket.emit (node:events:529:35)
    at node:net:350:12
    at TCP.done (node:_tls_wrap:657:7)
    at TCP.callbackTrampoline (node:internal/async_hooks:128:17) {
  type: 'system',
  errno: 'ECONNRESET',
  code: 'ECONNRESET'
}

And this is the function where its failing.

getProjectsPaginated: async (queryBody) => {
    try {
      const { query, maxResults, startAt } = queryBody;
      if (!jiraToken) {
        throw new Error(`JiraToken is missing`);
      }
      const jiraResponse = await fetch(
        `${jiraSiteUrl}/rest/api/3/project/search?${query}&startAt=${startAt}&maxResults=${maxResults}`,
        {
          method: "GET",
          headers: {
            Authorization: `Basic ${jiraToken}`,
            Accept: "*/*",
            "Content-Type": "application/json",
          },
        }
      );
      const data = await jiraResponseHandler(jiraResponse);
      return data;
    } catch (error) {
      console.error(`Error fetching paginated projects for the query:`, error);
      throw error;
    }

Hope this helps you understand the issue. Any solution would be greatly appreciated!

Cheers

Same problem here with an jira app, which is using the jira cloud rest api.