@fiverr/statsd-client
Advanced tools
Comparing version 1.0.2 to 1.0.3-rc-f1ece3e
@@ -15,3 +15,3 @@ const sample = require('sample-size'); | ||
accumulator, | ||
{[type]: type} | ||
{ [type]: type } | ||
), | ||
@@ -116,2 +116,4 @@ {} | ||
}); | ||
process.on('exit', this.flush); | ||
} | ||
@@ -177,2 +179,7 @@ | ||
} | ||
destroy() { | ||
process.off('exit', this.flush); | ||
this.send.destroy(); | ||
} | ||
} | ||
@@ -179,0 +186,0 @@ |
@@ -16,3 +16,3 @@ const isNumber = require('is-number'); | ||
*/ | ||
module.exports = function formatter({prefix, sanitise = sanitiser, scheme = 'datadog'} = {}) { | ||
module.exports = function formatter({ prefix, sanitise = sanitiser, scheme = 'datadog' } = {}) { | ||
if (prefix) { | ||
@@ -49,3 +49,3 @@ if (typeof prefix !== 'string') { | ||
accumulator, | ||
{[sanitise(key)]: sanitise(value)} | ||
{ [sanitise(key)]: sanitise(value) } | ||
), | ||
@@ -64,3 +64,3 @@ {} | ||
*/ | ||
return function format(type = 'count', key, value = 1, {rate, tags} = {}) { | ||
return function format(type = 'count', key, value = 1, { rate, tags } = {}) { | ||
if (type in types) { | ||
@@ -97,4 +97,4 @@ type = types[type]; | ||
return scheme({type, key, value, rate, tags}); | ||
return scheme({ type, key, value, rate, tags }); | ||
}; | ||
}; |
@@ -9,3 +9,3 @@ /** | ||
const {size} = this; | ||
const { size } = this; | ||
@@ -12,0 +12,0 @@ // Accumulated size does not surpass the MTU |
@@ -12,2 +12,9 @@ const { createConnection } = require('net'); | ||
/** | ||
* Socket is closing | ||
* @type {Boolean} | ||
*/ | ||
let closing = false; | ||
/** | ||
* Tear-down operation registered | ||
@@ -35,7 +42,19 @@ * @type {Boolean} | ||
function endSocket() { | ||
socket && socket.destroy(); | ||
if (closing) { | ||
return; | ||
} | ||
closing = true; | ||
socket && socket.end(derefSocket); | ||
process.off('exit', endSocket); | ||
} | ||
/** | ||
* De ref socket. Set "closing" to false | ||
* @return {undefined} | ||
*/ | ||
function derefSocket() { | ||
closing = false; | ||
socket = null; | ||
} | ||
/** | ||
@@ -56,17 +75,30 @@ * @typedef Send | ||
*/ | ||
module.exports = (port, host, errorHandler) => (data) => { | ||
if (!teardown) { | ||
process.on('exit', endSocket); | ||
teardown = true; | ||
module.exports = function createSender(port, host, errorHandler) { | ||
/** | ||
* Write data to TCP socket | ||
* @param {string} data | ||
* @returns {boolean} | ||
*/ | ||
function sender(data) { | ||
if (!teardown) { | ||
process.on('exit', endSocket); | ||
teardown = true; | ||
} | ||
return getSocket(port, host) | ||
.write( | ||
Buffer.from(data), | ||
ENCODING, | ||
(error) => { | ||
if (error) { | ||
endSocket(); | ||
errorHandler(error, data); | ||
} | ||
} | ||
); | ||
} | ||
return getSocket(port, host) | ||
.write( | ||
Buffer.from(data), | ||
ENCODING, | ||
(error) => { | ||
endSocket(); | ||
error && errorHandler(error, data); | ||
} | ||
); | ||
sender.destroy = endSocket; | ||
return sender; | ||
}; |
@@ -43,2 +43,3 @@ const { createSocket } = require('dgram'); | ||
socket && socket.close(derefSocket); | ||
process.off('exit', endSocket); | ||
} | ||
@@ -64,3 +65,3 @@ | ||
/** | ||
* Create a socket send method | ||
* createSender: Create a socket send method | ||
* @param {String} port | ||
@@ -71,21 +72,34 @@ * @param {String} host | ||
*/ | ||
module.exports = (port, host, sockettype, errorHandler) => (data) => { | ||
const buffer = Buffer.from(data); | ||
module.exports = function createSender(port, host, sockettype, errorHandler) { | ||
if (!teardown) { | ||
process.on('exit', endSocket); | ||
teardown = true; | ||
/** | ||
* Send data to UDP socket | ||
* @param {string} data | ||
*/ | ||
function sender(data) { | ||
const buffer = Buffer.from(data); | ||
if (!teardown) { | ||
process.on('exit', endSocket); | ||
teardown = true; | ||
} | ||
return getSocket(sockettype).send( | ||
buffer, | ||
0, | ||
buffer.length, | ||
port, | ||
host, | ||
(error) => { | ||
if (error) { | ||
endSocket(); | ||
errorHandler(error, data); | ||
} | ||
} | ||
); | ||
} | ||
getSocket(sockettype).send( | ||
buffer, | ||
0, | ||
buffer.length, | ||
port, | ||
host, | ||
(error) => { | ||
endSocket(); | ||
error && errorHandler(error, data); | ||
} | ||
); | ||
sender.destroy = endSocket; | ||
return sender; | ||
}; |
@@ -16,3 +16,3 @@ const sendTCP = require('../send-tcp'); | ||
*/ | ||
module.exports = function sender({host, port, protocol, protocol_version, errorHandler} = {}) { | ||
module.exports = function sender({ host, port, protocol, protocol_version, errorHandler } = {}) { | ||
if (protocol) { | ||
@@ -19,0 +19,0 @@ if (!PATTERN_PROTOCOL.test(protocol)) { |
@@ -19,3 +19,3 @@ /** | ||
if (typeof lastArg === 'object') { | ||
({rate, tags} = lastArg); | ||
({ rate, tags } = lastArg); | ||
([type, key, value] = args); | ||
@@ -22,0 +22,0 @@ } else { |
{ | ||
"name": "@fiverr/statsd-client", | ||
"version": "1.0.2", | ||
"version": "1.0.3-rc-f1ece3e", | ||
"description": "📈 A feature packed, highly customisable StatsD client", | ||
@@ -47,4 +47,4 @@ "keywords": [ | ||
"publishConfig": { | ||
"tag": "latest" | ||
"tag": "2020-04-16-fix-socket-premature-ending" | ||
} | ||
} |
@@ -8,3 +8,3 @@ const DELIMETER_KEY_VALUE = ':'; | ||
module.exports = function scheme({type, key, value, rate, tags}) { | ||
module.exports = function scheme({ type, key, value, rate, tags }) { | ||
const parts = [ | ||
@@ -11,0 +11,0 @@ key, |
@@ -8,3 +8,3 @@ const DELIMETER_KEY_VALUE = ':'; | ||
module.exports = function scheme({type, key, value, rate, tags}) { | ||
module.exports = function scheme({ type, key, value, rate, tags }) { | ||
const parts = [key]; | ||
@@ -11,0 +11,0 @@ tags && parts.push(DELIMETER_TAGS, tagsString(tags)); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25460
630
1