Socket hang up



  • Hi,
    I am getting the error below when I attempt to call a report dynamically within another report:
    2018-12-11T15:33:26.456Z - warn: Error when processing render request socket hang up Error: socket hang up at createHangUpError (_http_client.js:322:15) at Socket.socketOnEnd (_http_client.js:425:23) at Socket.emit (events.js:187:15) at endReadableNT (_stream_readable.js:1085:12) at process._tickCallback (internal/process/next_tick.js:63:19)

    Here is my scenario:
    I am using the beforeRender function (I have added the 'async' attribute to the method) and then call a dynamic jsreport (to populate SQL string with parameters) like so:

    async function renderDynamicTemplate(templateObject) { let defaultTemplateObject = { template: { content: "", engine: "jsrender", recipe: "text" }, data: {}, options: { "timeout": 1000 } } Object.assign(defaultTemplateObject, templateObject); let result = await jsreport.render(defaultTemplateObject); return result.content.toString(); }

    This works fine in my development environment but when I run this in docker I get the above error.

    I looked around and some people said that net-cluster might be the source of the issue so I have tried switching to 'dedicated-process' in my config for templatingEngines (which should avoid the use of that library) but the issue persists.

    Any thoughts? Could the 'async' modifier on beforeRender be causing the issue? I guess I don't understand why it works in nodejs on my machine but not in docker.

    Thanks,
    Jeremiah



  • Hm. Maybe the rendering of the dynamic template somehow crashes?
    Do you use official docker image? What version?

    Trying something like this in the docker image 2.2.0 and it works

    const proxy = require('jsreport-proxy')
    
    async function beforeRender(req, res) {
      const result = await proxy.render({ template: { content: 'another', engine: 'none', recipe: 'text' } })  
      req.template.content = result.content.toString()
    }
    

    Also in playground such script works
    https://playground.jsreport.net/w/jan_blaha/CoDLg8j4



  • Yes using the official docker image jsreport/jsreport. I have tried the same code with docker 2.2.0-full as well, same issue.

    I will try your script to see if i get the same error.

    Thanks!



  • @jan_blaha - this is still the error:
    /usr/local/bin/node[33]: ../src/tcp_wrap.cc:136:static void node::TCPWrap::New(const v8::FunctionCallbackInfov8::Value&): Assertion `args[0]->IsInt32()' failed.
    2018-12-12T05:24:26.953Z - warn: Error when processing render request socket hang up Error: socket hang up
    at createHangUpError (_http_client.js:322:15)
    at Socket.socketOnEnd (_http_client.js:425:23)
    at Socket.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1085:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    2018-12-12T05:24:26.956Z - warn: Error during processing request at http://localhost/api/report

    To be clear, I am defining proxy as such:
    const proxy = require('jsreport');

    I see in the documentation a module called 'jsreport-proxy' but i can not find that on npm nor in the jsreport project files. Am I missing something?

    Again, this identical code works on non-docker images. I'm curious if some dependency is trying to access restricted system resources?



  • the require('jsreport') creates completely new jsreport instance.
    The require('jsreport-proxy') is a bridge from the script to the current jsreport instance.
    You don't install it. It is kind of virtual mock we provide to the script.
    Creating a new jsreport instance can have collisions with the current one.
    You should not do that.

    Does it fail also when using require('jsreport-proxy')?



  • Yes that fixed it!!

    Something odd though. I am using a global asset helper for most of my code (using {#asset global-helpers.js @encoding=utf8}).
    When I put the const proxy = require('jsreport-proxy'); at the top of the script file itself it runs fine. But when i put the include statement inside the global-helpers.js file i get the following error:

    2018-12-12T15:43:13.741Z - warn: Error when processing render request Error while executing templating engine. Unable to find module jsreport-proxy
    Searched paths:
    jsreport-proxy
    jsreport-proxy
    /app/jsreport-proxy
    /app/jsreport-proxy
    /app/jsreport-proxy
    .

    3 |
    4 |

    5 | const proxy = require('jsreport-proxy');
    | ^
    6 |

    Error: Unable to find module jsreport-proxy
    Searched paths:
    jsreport-proxy
    jsreport-proxy
    /app/jsreport-proxy
    /app/jsreport-proxy
    /app/jsreport-proxy

    at doRequire (/app/node_modules/jsreport-core/lib/render/safeSandbox.js:213:11)
    at _require (/app/node_modules/jsreport-core/lib/render/safeSandbox.js:54:14)
    at Object.apply (/app/node_modules/vm2/lib/contextify.js:288:34)
    at evaluate-template-engine-helpers.js:5:15
    at Script.runInContext (vm.js:101:20)
    at VM.run (/app/node_modules/vm2/lib/main.js:212:72)
    at run (/app/node_modules/jsreport-core/lib/render/safeSandbox.js:171:19)
    at module.exports (/app/node_modules/jsreport-core/lib/render/engineScript.js:114:7)
    at IncomingMessage.<anonymous> (/app/node_modules/script-manager/lib/worker-servers.js:239:47)
    at IncomingMessage.emit (events.js:182:13)
    at IncomingMessage.EventEmitter.emit (domain.js:460:23)
    at endReadableNT (_stream_readable.js:1085:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)


  • The jsreport-proxy is allowed only in the jsreport scripts
    https://jsreport.net/learn/scripts

    It is not supported in the templating engines, because it is anyway asynchronous and templating engine supports only sync functions.
    If you put it to your global asset helpers, it gets extracted into the templating engine helpers and crashes.


Log in to reply
 

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