diff --git a/CHANGES.md b/CHANGES.md index 1e721bc..12f8d04 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,10 @@ CHANGELOG ========= +## 9.1.0 (2022-6-20) +* @bdeitte Update testing dependencies +* @bdeitte Check if client is undefined before closing to fix error + ## 9.0.0 (2021-10-31) * @cesarfd Add TCP reconnections, similar to how it's done for UDS. Enabled by default and configurable through tcpGracefulErrorHandling/tcpGracefulRestartRateLimit. * @sambostock Document explicit prefix/suffix separators diff --git a/lib/statsd.js b/lib/statsd.js index 2734057..c392739 100644 --- a/lib/statsd.js +++ b/lib/statsd.js @@ -433,6 +433,14 @@ Client.prototype.close = function (callback) { * Really close the socket and handle any errors related to it */ Client.prototype._close = function (callback) { + // If there was an error creating it, nothing to do here + if (! this.socket) { + if (callback) { + callback(); + } + return; + } + // error function to use in callback and catch below let handledError = false; const handleErr = (err) => { @@ -534,7 +542,7 @@ exports.StatsD = Client; * @param err The error that we will handle if a TCP/UDS connection error is detected. */ function protocolErrorHandler(client, protocol, err) { - if (!err || !client.socket.createdAt) { + if (!err || !client.socket || !client.socket.createdAt) { return; }