diff --git a/CHANGELOG.md b/CHANGELOG.md index d9d5d31..4200f20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the LaunchDarkly Node.js SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org). +## [4.0.3] - 2018-03-27 +### Fixed +- Fixed a [bug](https://github.com/launchdarkly/node-client/issues/85) that would cause an unhandled promise rejection warning-- and, depending on your Node configuration, a crash-- if there was an HTTP error during an automatic event flush. + ## [4.0.2] - 2018-03-14 ### Fixed - In the Redis feature store, fixed synchronization problems that could cause a feature flag update to be missed if several of them happened in rapid succession. diff --git a/index.js b/index.js index a470053..95ef832 100644 --- a/index.js +++ b/index.js @@ -39,7 +39,8 @@ var new_client = function(sdk_key, config) { queue = [], requestor, update_processor, - event_queue_shutdown = false; + event_queue_shutdown = false, + flush_timer; config = Object.assign({}, config || {}); config.user_agent = 'NodeJSClient/' + package_json.version; @@ -241,6 +242,7 @@ var new_client = function(sdk_key, config) { update_processor.close(); } config.feature_store.close(); + clearInterval(flush_timer); } client.is_offline = function() { @@ -334,8 +336,11 @@ var new_client = function(sdk_key, config) { enqueue(event); } - // TODO keep the reference and stop flushing after close - setInterval(client.flush.bind(client), config.flush_interval * 1000).unref(); + function background_flush() { + client.flush().then(function() {}, function() {}); + } + + flush_timer = setInterval(background_flush, config.flush_interval * 1000); return client; }; diff --git a/package.json b/package.json index 9bee3fe..686e561 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ldclient-node", - "version": "4.0.2", + "version": "4.0.3", "description": "LaunchDarkly SDK for Node.js", "main": "index.js", "scripts": {