Skip to content

Commit

Permalink
Merge pull request #37 from auth0/PSERV-1561_reconnect_on_readonly_error
Browse files Browse the repository at this point in the history
fix: Reconnect when readonly error is received from redis in Limitr client
  • Loading branch information
joseluisdiaz authored Mar 7, 2023
2 parents a502ddd + 37088f7 commit 4924906
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ class LimitDBRedis extends EventEmitter {
enableOfflineQueue: false,
keyPrefix: config.prefix,
password: config.password,
tls: config.tls
tls: config.tls,
reconnectOnError: (err) => {
// will force a reconnect when error starts with `READONLY`
// this code is only triggered when auto-failover is disabled
// more: https://github.com/luin/ioredis#reconnect-on-error
return err.message.includes('READONLY');
},
};

const clusterOptions = {
Expand Down Expand Up @@ -325,7 +331,7 @@ class LimitDBRedis extends EventEmitter {
}, callback);
}

_determineCount({paramsCount, defaultCount, bucketKeyConfigSize}) {
_determineCount({ paramsCount, defaultCount, bucketKeyConfigSize }) {
if (paramsCount === 'all') {
return bucketKeyConfigSize;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dependencies": {
"async": "^2.6.1",
"disyuntor": "^3.5.0",
"ioredis": "^4.5.1",
"ioredis": "^4.28.5",
"lodash": "^4.17.15",
"lru-cache": "^4.1.5",
"ms": "^2.1.2",
Expand Down

0 comments on commit 4924906

Please sign in to comment.