JS heap out of memory - bwip-js



  • Hello there
    thank you for the fantastic product you have created!

    I'm using the jsreport to generate a PDF with a barcode (actually 2x barcodes but that is not relevant) and I'm experiencing an error with the heap memory.
    I've seen others had similar issues already but in this case I think it may be different, maybe I'm doing something wrong.

    The settings:

    {
      "trustUserCode": true,
      "store": {
        "provider": "fs"
      },
      "logger": {
        "console": {
          "transport": "console",
          "level": "info"
        }
      },
      "workers": {
        "numberOfWorkers": 2
      },
      "templatingEngines": {
        "timeout": 600000,
        "strategy": "http-server"
      },
      "chrome": {
        "strategy": "chrome-pool"
      },
      "extensions": {
        "express": {
          "renderTimeout": 600000
        }
      }
    }
    

    There is only 1x template and for the test it only contains single paragraph with static text. What is causing the problem is the script (shared global, I have also tried it as the template script)

    const bwipjs = require('bwip-js');
    

    I have followed the steps here https://jsreport.net/blog/barcode-in-report#wrap to get the barcode up & running.

    Using the Apache jmeter to run some load (2x users, infinite loop until error occurs) I can relatively quickly get the heap error. This is how I run the docker

     docker run -e NODE_OPTIONS=--max-old-space-size=768 -m 1024m -p 5488:5488 jsreportlocal
    

    I use handlebars, chrome-pdf to generate the PDF.

    It looks like some sort of memory leak but I do not why. Any advise would be much appreciated.



  • Can you try exactly this code in helpers

    const bwipjs = require('bwip-js');
    
    function barcode()  {
      return bwipjs.toBuffer({
        bcid:  'code128',
        text:  '0123456789',
        scale:  3,
        height:  10,
        includetext:  true,
        textxalign:  'center',
      }).then(p => p.toString('base64'))
    }
    

    and this content in template

    <img  src='data:image/png;base64,{{barcode}}' />
    

    If you loop such template render, does it also OOM?
    What jsreport version do you use? Can you try the latest?



  • Hello
    I have tried it (again) with the exact method body and it failed again.

    error: Error during processing request at http://localhost:5488/api/report, details: Error [WORKER_CRASHED]: Worker terminated due to reaching memory limit: JS heap out of memory
        at new NodeError (node:internal/errors:387:5)
        at Worker.[kOnExit] (node:internal/worker:285:26)
        at Worker.<computed>.onexit (node:internal/worker:202:20)
    

    I have jsreport 3.11.3, see below.

    0_1683205624435_upload-ab92b8d1-d0c9-4913-97b5-a256eed9d5d6



  • I have tried to remove the bwip-js and used some other package (pretty much random), so I used axios, but only like this

    const axios = require('axios');
    

    The jsreport under load survived 27mins, then I got the heap error. I'm not sure this is relevant but it feels like something is not released correctly.



  • It could be as you say. We are checking on it now. Will post here as soon as we have details.



  • Update: This is actually really a bug. It is likely a nodejs bug that started to occur since nodejs 16.
    We've implemented a workaround which we are testing now.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.