From 8b6cef49495410e92c27881648935e66b560d45a Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Tue, 27 Mar 2018 16:08:29 -0700 Subject: [PATCH 1/2] avoid unhandled promise rejection when automatically flushing --- index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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; }; From 71982bf08b898b32d684c7fc5fdb43a82e169dbc Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Tue, 27 Mar 2018 16:15:42 -0700 Subject: [PATCH 2/2] 4.0.3 release --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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/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": {