Skip to content

Potential memory leak in services/api/index.ts #21

Open
@jasnell

Description

In the connected function in https://github.com/covidgreen/covid-green-app/blob/current/services/api/index.ts#L47-L60 https://github.com/covidgreen/covid-green-app/blob/current/src/services/api/index.ts#L46-L59, when retry is true and the network is not available, the function recursively awaits on itself. This sets up a memory leak when the network is unavailable for a protracted period of time (memory leak in that the Promise chain will grow indefinitely while waiting for the network to become available.

The code in question is copied below:

const connected = async (retry = false): Promise<boolean> => {
  const networkState = await NetInfo.fetch();
  if (networkState.isInternetReachable && networkState.isConnected) {
    return true;
  }

  if (retry) {
    throw new Error('Network Unavailable');
  } else {
    await new Promise((r) => setTimeout(r, 1000));
    await connected(true);
    return true;
  }
};

This should be refactored to avoid the recursion.

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions