Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

statsd-client

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

statsd-client - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

36

lib/EphemeralSocket.js

@@ -11,3 +11,3 @@ var dgram = require('dgram');

this.options.debug = this.options.debug || false;
this.options.socket_timeout = this.options.socket_timeout || 1000;
this.options.socketTimeout = this.options.socketTimeout || 1000;

@@ -21,6 +21,6 @@ // Set up re-usable socket

/*
* Check if the socket has been used in the previous socket_timeout-interval.
* Check if the socket has been used in the previous socketTimeout-interval.
* If it has, we leave it open and try again later. If it hasn't, close it.
*/
EphemeralSocket.prototype._socket_timeout = function () {
EphemeralSocket.prototype._socketTimeout = function () {
// Is it already closed? -- then stop here

@@ -50,5 +50,2 @@ if (!this._socket) {

//Make sure further errors do not propagate upwards
this._socket.on("error", function () {});
// Cancel the running timer

@@ -58,9 +55,20 @@ clearInterval(this._socketTimer);

// Wait a tick or two, so any remaining stats can be sent.
var that = this;
setTimeout(function () {
that._socket.close();
that._socket = undefined;
}, 10);
setTimeout(this.kill.bind(this), 10);
};
/* Kill the socket RIGHT NOW.
*/
EphemeralSocket.prototype.kill = function () {
if (!this._socket) {
return;
}
// Clear the timer and catch any further errors silently
clearInterval(this._socketTimer);
this._socket.on('error', function () {});
this._socket.close();
this._socket = undefined;
};
EphemeralSocket.prototype._createSocket = function (callback) {

@@ -77,3 +85,3 @@ var that = this;

// later.
this._socket.once('error', this.close.bind(this));
this._socket.once('error', this.kill.bind(this));

@@ -87,4 +95,4 @@ // Call on when the socket is ready.

// Start timer, if we have a positive timeout
if (this.options.socket_timeout > 0) {
this._socketTimer = setInterval(this._socket_timeout.bind(this), this.options.socket_timeout);
if (this.options.socketTimeout > 0) {
this._socketTimer = setInterval(this._socketTimeout.bind(this), this.options.socketTimeout);
}

@@ -91,0 +99,0 @@ };

@@ -27,10 +27,12 @@ /*

client.increment('response.' + res.statusCode);
if (timeByUrl && req.route && req.route.path) {
var routeName;
client.increment('response_code.' + res.statusCode);
// Time by URL?
if (timeByUrl) {
var routeName = "unknown_express_route";
// Did we get a harc-coded name, or should we figure one out?
if (res.locals && res.locals.statsdUrlKey) {
routeName = res.locals.statsdUrlKey;
} else {
} else if (req.route && req.route.path) {
routeName = req.route.path;

@@ -37,0 +39,0 @@ if (Object.prototype.toString.call(routeName) === '[object RegExp]') {

@@ -6,3 +6,3 @@ {

"keywords": ["statsd", "client", "metrics", "udp"],
"version": "0.0.11",
"version": "0.0.12",
"homepage": "https://github.com/msiebuhr/node-statsd-client",

@@ -9,0 +9,0 @@ "bugs": "https://github.com/msiebuhr/node-statsd-client/issues",

@@ -115,2 +115,11 @@ node-statsd-client

It can also measure per-URL (e.g. PUT to `/:user/:thing` will become
`PUT_user_thing` by setting the `timeByUrl: true` in the `options`-object:
app.use(sdc.helpers.getExpressMiddleware('prefix', { timeByUrl: true }));
As the names can become rather odd in corner-cases (esp. regexes and non-REST
interfaces), you can specify another value by setting `res.locals.statsdUrlKey`
at a later point.
### Stopping gracefully

@@ -117,0 +126,0 @@

@@ -53,11 +53,16 @@ /* Test the Ephemeral socket

it("Does not crash when many errors are emitted", function (done) {
e._createSocket(function () {
e._socket.emit('error');
e._socket.emit('error');
e._socket.emit('error');
var s = new EphemeralSocket();
s._createSocket(function () {
function emitError() {
if (s._socket) {
s._socket.emit('error');
process.nextTick(emitError);
}
}
emitError();
setTimeout(function () {
assert.isUndefined(e._socket);
assert(!s._socket, "Socket isn't closed.");
done();
}, 15);
}, 5);
});

@@ -70,3 +75,3 @@ });

te = new EphemeralSocket({
socket_timeout: 1
socketTimeout: 1
});

@@ -73,0 +78,0 @@ te._createSocket(done);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc