Skip to content

Commit

Permalink
fix: handle redis client error events
Browse files Browse the repository at this point in the history
  • Loading branch information
dnechay committed Sep 3, 2024
1 parent 6e779aa commit 853c997
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const redis = require('redis');
const Scripty = require('node-redis-scripty');
const { EventEmitter } = require('events');

const noop = () => {};

/**
* Lock constructor.
*
Expand Down Expand Up @@ -46,6 +48,15 @@ class Lock {
this._redisConnection = redis.createClient(options.redis);
this._redisSubscriber = redis.createClient(options.redis);
}
/**
* Since subscriber client is created implicitly and
* it's being and instance of EventEmitter,
* we have to subscribe on error events in order to not
* cause crashes where this library is used.
*
* https://nodejs.org/api/events.html#error-events
*/
this._redisSubscriber.on('error', noop);

// Handler to run LUA scripts. Uses caching if possible
this._scripty = new Scripty(this._redisConnection);
Expand Down

0 comments on commit 853c997

Please sign in to comment.