Skip to content

Using command that returns large json doesn't work #2

@tflowcamdev

Description

@tflowcamdev

I've been using this package with success but lately found an issue when I execute a command that will return a large json.

The issue appears to be that node is chunking the std out data, but each chunk is assumed to be a complete command response (or multiple command responses).

I'll attach a sample fix that works for me - essentially assuming that if data doesn't end with a newline we're getting an incomplete chunk of data, so keep appending and then process once we have a data chunk that is on a command response boundary

Sample fix in gonode.js:

// Receive data from go-module
function handleStdout(go, data) {
   go.stdoutData += data;

    // Response may be several command responses separated by new lines
   var dataSplit = go.stdoutData.toString().split("\n");
   if (dataSplit[dataSplit.length-1].length === 0) {
     // Data ended on \n so assume we have a complete command output (or complete set of cmmand outputs),
     // process the full stdout data
     dataSplit.forEach(function(resp) {
       // Discard empty lines
       if(resp.length > 0) {
         // Parse each command response with a event-loop in between to avoid blocking
         process.nextTick(function(){parseResponse(go, resp)});
       }
     });
     // Reset stdoutData
     go.stdoutData = '';
   }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions