nmarus / node-ews

A simple JSON wrapper for the Exchange Web Services (EWS) SOAP API.
MIT License
115 stars 52 forks source link

Potential memory leak problem of ews.run function #104

Closed jeffreyleeon closed 5 years ago

jeffreyleeon commented 5 years ago

Hi CumberlandGroup,

First thank you for developing node-ews, it saves me a lot of time interacting with email client. Recently, I am head an issue that my production server having issue of

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

After some research, our team found that many strings are created and persisted in the running node until all the memory used up.

memory_leak

And we continue deep diving and found out that ews.run('FindFolder') calls caused the memory leak. Below is the sample program to reproduce the memory leak. (Version node-ews@3.2.4)

Sorry the disturb, but would like to know did we misused the library thus causing memory leak? Thank you.

var EWS = require('node-ews');
var cron = require('node-cron');

var ewsConfig = {
  username: 'YOUR_EMAIL',
  password: 'YOUR_PASSWORD',
  host: 'YOUR_HOST'
};

const ewsSoapHeader = {
  't:RequestServerVersion': {
    attributes: {
      Version: "Exchange2013"
    }
  }
};

const ews = new EWS(ewsConfig);

var ewsArgs = {
   'attributes' : {
      'Traversal' : 'Deep'
   },
   'FolderShape' : {
     'BaseShape': 'AllProperties'
   },
   'ParentFolderIds' : {
    'DistinguishedFolderId' : {
      'attributes' : {
        'Id' : 'inbox'
      }
    }
   }
};

function leak() {
    ews.run('FindFolder', ewsArgs, ewsSoapHeader)
      .then(result => {
        console.log(JSON.stringify(result));
      })
      .catch(err => {
        console.log(err.stack);
      });
}

cron.schedule('*/10 * * * * *', leak);
samsonoveu commented 5 years ago

Solved in other issue.

And keep in mind also that without that 'temp:' parameter it creates a new folder with its own data for each request in /tmp that takes a lot of storage after many requests.

jeffreyleeon commented 5 years ago

Thanks @samsonoveu, Will give this a try!