Skip to content

Commit

Permalink
Merge pull request #36 from mixmaxhq/dnechay/RCA-262
Browse files Browse the repository at this point in the history
fix: handle redis client error events
  • Loading branch information
dnechay authored Sep 4, 2024
2 parents 6e779aa + 20df862 commit 594ba06
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 an 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 594ba06

Please sign in to comment.