Wednesday, 15 March 2017

Node.js node_http_parser error: Assertion `!current_buffer' failed

node: ../src/node_http_parser.cc:387: static v8::Handle<v8::Value>
node::Parser::Execute(const v8::Arguments&): Assertion `!current_buffer' failed.

This is the exact error I'm getting when I try to execute the following code as part of my Node server:

function fetchItem(idSection, queryURL){

    var item = {};

    // forced sync
    var readyToContinue = false;

    // execute query
    var options = {
        url:  queryURL,
        timeout: 2000
    }
    var request = require('request');
    request(options, function (error, response, body) {
        if (error){
            console.log('[ERROR] Request error: ', error);
            // release control
            readyToContinue = true;
        }
        else {
            // extract data from response body
            var response = JSON.parse(body).response;
            if (response.numFound > 0){
                var doc = response.docs[0];

                // create item object and store it
                item.name = doc.name;
                item.link = doc.link;
                item.image_link = doc.thumb_s;
            }
            // release control
            readyToContinue = true;
        }
    });
    // hold execution until readyToContinue
    while(!readyToContinue) {
        require('deasync').runLoopOnce();
    }
    return item;
}

The annoying/confusing part is that the request works fine when running locally on my machine, but the app crashes when I run it on one of our dev servers. Very grateful for any help on this.

NOTE: I force synchronised behaviour because I need multiple queries to execute in sequence - I appreciate that a number of replies are likely to be chastising me for not executing asynchronously...



via HomerPlata

No comments:

Post a Comment