Skip to content

Commit

Permalink
Merge pull request #227 from brightcove/client_undefined_check
Browse files Browse the repository at this point in the history
Check if client is undefined to fix errors
  • Loading branch information
bdeitte authored Jun 20, 2022
2 parents 2a6f459 + 74e02fa commit cd447a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 9 additions & 1 deletion lib/statsd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit cd447a2

Please sign in to comment.