keen / keen-js

https://keen.io/ JavaScript SDKs. Track users and visualise the results. Demo http://keen.github.io/keen-dataviz.js/
MIT License
578 stars 143 forks source link

NodeJs hangs #432

Closed TheCodeKing closed 7 years ago

TheCodeKing commented 7 years ago

In NodeJs it just hangs when using the library. e.g the following example returns success, but never exits.

npm i keen-js

var Keen = require('keen-js');

var client = new Keen({
  projectId: "YOUR_PROJECT_ID",
  writeKey: "YOUR_WRITE_KEY"
});

var purchaseEvent = {
  id: 1111,
  item: 'golden gadget',
  price: 25.50,
  referrer: 'nodejs',
  keen: {
    timestamp: new Date().toISOString()
  }
};

client.recordEvent('purchases', purchaseEvent, (err, res) => {
  if (err) {
    console.log(err);
  }
  else {
    console.log(res);
  }
});
tbarn commented 7 years ago

Confirmed this issue with someone else too, looks like something is causing Node from closing. Looking into now.

dustinlarimer commented 7 years ago

@TheCodeKing thanks for reporting- to help us triage a bit better, can you share which version of keen-js you're running?

TheCodeKing commented 7 years ago

Sure sorry, should have mentioned. It's node version v7.9.0 with keen-js 4.0.1.

dustinlarimer commented 7 years ago

@TheCodeKing I tracked the issue down. If you're not using the deferEvent queueing mechanism (assuming you're not) call client.queueInterval(0); after instantiating the client. This will allow the process to exit properly.

This is a bug and cant be tracked here: https://github.com/keen/keen-tracking.js/issues/84

TheCodeKing commented 7 years ago

Great thanks for the workaround.

dustinlarimer commented 7 years ago

@TheCodeKing this fix has been released with v4.1.0 – thanks for helping triage this one! 🚀