hot-shots
Advanced tools
Comparing version 6.5.1 to 6.6.0
CHANGELOG | ||
========= | ||
## 6.6.0 (2019-10-7 | ||
* @NinjaBanjo @msiebuhr Add udsGracefulErrorHandling, ensuring uds | ||
handles socket errors gracefully | ||
## 6.5.1 (2019-9-28) | ||
@msiebuhr Fix crasher when closing Unix Datagram Sockets without callback | ||
* @msiebuhr Fix crasher when closing Unix Datagram Sockets without callback | ||
@@ -7,0 +11,0 @@ ## 6.5.0 (2019-9-22) |
@@ -16,2 +16,3 @@ const dgram = require('dgram'), | ||
const UDS_PATH_DEFAULT = '/var/run/datadog/dsd.socket'; | ||
const UDS_DEFAULT_GRACEFUL_RESTART_LIMIT = 1000; | ||
@@ -124,2 +125,3 @@ /** | ||
this.errorHandler = options.errorHandler; | ||
this.udsGracefulErrorHandling = 'udsGracefulErrorHandling' in options ? options.udsGracefulErrorHandling : true; | ||
@@ -158,2 +160,43 @@ // If we're mocking the client, create a buffer to record the outgoing calls. | ||
// only for uds (options.protocol uds) | ||
// enabled with the extra flag options.udsGracefulErrorHandling | ||
// will gracefully (attempt) to re-open the socket with a small delay | ||
// options.udsGracefulRestartRateLimit is the minimum time (ms) between creating sockets | ||
// does not support options.isChild (how to re-create a socket you didn't create?) | ||
if (!options.isChild && options.protocol === 'uds' && options.udsGracefulErrorHandling) { | ||
const socketCreateLimit = options.udsGracefulRestartRateLimit || UDS_DEFAULT_GRACEFUL_RESTART_LIMIT; // only recreate once per second | ||
const lastSocketCreateTime = Date.now(); | ||
this.socket.on('error', (err) => { | ||
const code = err.code; | ||
switch (code) { | ||
case 107: | ||
case 111: { | ||
if (Date.now() - lastSocketCreateTime >= socketCreateLimit) { | ||
// recreate the socket, but only once per 30 seconds | ||
if (this.errorHandler) { | ||
this.socket.removeListener('error', this.errorHandler); | ||
} | ||
this.socket.close(); | ||
this.socket = createSocket(this, { | ||
host: this.host, | ||
path: options.path, | ||
port: this.port, | ||
protocol: this.protocol | ||
}); | ||
if (this.errorHandler) { | ||
this.socket.on('error', this.errorHandler); | ||
} else { | ||
this.socket.on('error', error => console.error(`hot-shots UDS error: ${error}`)); | ||
} | ||
} | ||
break; | ||
} | ||
default: { | ||
break; | ||
} | ||
} | ||
}); | ||
} | ||
if (options.useDefaultRoute) { | ||
@@ -160,0 +203,0 @@ const defaultRoute = helpers.getDefaultRoute(); |
{ | ||
"name": "hot-shots", | ||
"description": "Node.js client for StatsD, DogStatsD, and Telegraf", | ||
"version": "6.5.1", | ||
"version": "6.6.0", | ||
"author": "Steve Ivy", | ||
@@ -6,0 +6,0 @@ "types": "./types.d.ts", |
@@ -50,2 +50,4 @@ # hot-shots | ||
* `path`: Used only when the protocol is `uds`. Defaults to `/var/run/datadog/dsd.socket`. | ||
* `udsGracefulErrorHandling`: Used only when the protocol is `uds`. Boolean indicating whether to handle socket errors gracefully. Defaults to true. | ||
* `udsGracefulRestartRateLimit`: Used only when the protocol is `uds`. Time (ms) between re-creating the socket. Defaults to `1000`. | ||
@@ -52,0 +54,0 @@ ### StatsD methods |
70335
1329
268