node-osmosis icon indicating copy to clipboard operation
node-osmosis copied to clipboard

Memory leak around async operations

Open dbousamra opened this issue 8 years ago • 1 comments

I have some code:

osmosis.get(url + '?page=', { page: 1 })
  .config({
    tries: 1,
    concurrency: 1
  })
  .paginate({ page: + 1 }, 100)
  .find('.thumbnail-item')
  .follow('@href')
  .set({
    'imageUrl': "img@src"
  })
  .then((document, data, next, done) => {
    const sanitized = _.mapValues(data, sanitize)
    return downloadImage(sanitized.imageUrl).then((res) => {
      next(document, data)
      done()
    }).catch((err) => {
      next(document, data)
      done()
    })
  })
  .debug(console.log)
  .log(console.log)
  .error(console.log)
  .done()

Downloading an image takes quite a while. My stack is building up heavily:

(get) stack: 81, requests: 707 (2 queued), RAM: 1123.88Mb (+0.00Mb), libxml: 3.5% (301k nodes), heap: 91% of 1007.08Mb
(follow) loaded [get] omitted
(find) found 1 results for ".camera-details"
(follow) loaded [get] omitted
(get) stack: 68, requests: 707 (0 queued), RAM: 1139.04Mb (+15.16Mb), libxml: 3.5% (303k nodes), heap: 94% of 1022.89Mb
(find) found 1 results for ".camera-details"
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1:
<--- Last few GCs --->
crawler          |
 1039540 ms: Mark-sweep 1375.9 (1420.1) -> 1375.9 (1436.1) MB, 109.4 / 0.0 ms [allocation failure] [scavenge might not succeed].
 1039642 ms: Mark-sweep 1375.9 (1436.1) -> 1375.9 (1436.1) MB, 102.1 / 0.0 ms [allocation failure] [scavenge might not succeed].
 1039745 ms: Mark-sweep 1375.9 (1436.1) -> 1375.9 (1420.1) MB, 102.2 / 0.0 ms [last resort gc].
 1039852 ms: Mark-sweep 1375.9 (1420.1) -> 1375.9 (1420.1) MB, 107.2 / 0.0 ms [last resort gc].

Any ideas?

dbousamra avatar Aug 23 '17 05:08 dbousamra

Try this:

Cu4rach4 avatar Dec 30 '19 11:12 Cu4rach4