From b15f0b2482794ec4001dd473f880936e46aaf639 Mon Sep 17 00:00:00 2001 From: Kevin Cheng Date: Fri, 3 Feb 2017 18:34:06 -0800 Subject: [PATCH] Await reconnect before job flush (#28) * wait for a keepalive from the server before re-running jobs on disconnect * 4.0.19 * jshint fix * Handle NULL_TYPE and INT_TYPE when parsing binary data batches * 4.0.20 --- lib/client/signalflow/request_manager.js | 12 ++++++++---- package.json | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/client/signalflow/request_manager.js b/lib/client/signalflow/request_manager.js index 6a13f9a..2bdb947 100644 --- a/lib/client/signalflow/request_manager.js +++ b/lib/client/signalflow/request_manager.js @@ -16,6 +16,7 @@ var SSE = require('sse.js'); function RequestManager(endPoint) { + var awaitingKeepaliveConfirmation = false; var knownComputations = {}; var requestIdIndex = 0; var maxJobCount = 10000; @@ -53,6 +54,12 @@ function RequestManager(endPoint) { var parsedMsg = sfxWSMsgHandler.parseWebSocketMessage(msg, knownComputations); if (parsedMsg.event === 'KEEP_ALIVE') { lastKeepAliveTime = Date.now(); + if (awaitingKeepaliveConfirmation) { + Object.keys(knownComputations).forEach(function (computation) { + knownComputations[computation].streamController.retry(); + }); + awaitingKeepaliveConfirmation = false; + } } if (parsedMsg.event === 'JOB_START') { @@ -118,9 +125,7 @@ function RequestManager(endPoint) { function reconnect(token) { wsConnectionOpen = false; authenticate(token); - Object.keys(knownComputations).forEach(function (computation) { - knownComputations[computation].streamController.retry(); - }); + awaitingKeepaliveConfirmation = true; } function authenticate(token) { @@ -146,7 +151,6 @@ function RequestManager(endPoint) { activeSocket.close(); } - activeSocket = new WebSocket(wsEndpoint + '/v2/signalflow/connect'); activeSocket.binaryType = 'arraybuffer'; activeSocket.onmessage = onWebSocketMessage; diff --git a/package.json b/package.json index 289c594..3a8d6b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "signalfx", - "version": "4.0.19", + "version": "4.0.20", "description": "Node.js client library for SignalFx", "homepage": "https://signalfx.com", "repository": "https://github.com/signalfx/signalfx-nodejs",