Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if client is undefined to fix errors #227

Merged
merged 3 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -426,6 +426,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 @@ -527,7 +535,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