appbaseio / appbase-js

appbase.io search client library for JavaScript
MIT License
42 stars 18 forks source link

stream response has side-effects #10

Closed siddharthlatest closed 8 years ago

siddharthlatest commented 8 years ago

Running two searchStream() methods with the same query object and mutating on the resulting data of one of the streams similarly mutates the resulting data of the other stream.

The lib should use immutable before returning the object to avoid side effects.

Code to reproduce the bug - multiple-streams-bug.js, output shown below:

var Appbase = require('appbase-js')

var appbaseRef = new Appbase({
  url: 'https://RIvfxo1u1:dee8ee52-8b75-4b5b-be4f-9df3c364f59f@scalr.api.appbase.io',
  appname: 'createnewtestapp01'
})

appbaseRef.searchStream({
  type: ["book", "product", "TestType"],
  body: {
    query: { match_all: {}}
  }
}).on('data', function(res) {
  console.log("response#1: ", res);
  res._source = 'foo';
}).on('error', function(err) {
  console.log("caught a streaming error", err);
})

appbaseRef.searchStream({
  type: ["book", "product", "TestType"],
  body: {
    query: { match_all: {}}
  }
}).on('data', function(res) {
  console.log("response#2: ", res);
}).on('error', function(err) {
  console.log("caught a streaming error: ", err);
})

Console output

siddharthlatest commented 8 years ago

Fixed in v0.10.7.