Cluster UnhandledPromiseRejectionWarning
See original GitHub issueI’m intentionally causing a connection error (by omitting a NAT mapping for one cluster node) to verify my application’s error handling, but I’m seeing an UnhandledPromiseRejectionWarning:
(node:18) UnhandledPromiseRejectionWarning: Error: Connection is closed.
at close (/home/node/app/node_modules/ioredis/built/redis/event_handler.js:102:25)
at Socket.<anonymous> (/home/node/app/node_modules/ioredis/built/redis/event_handler.js:73:20)
at Object.onceWrapper (events.js:288:20)
at Socket.emit (events.js:200:13)
at Socket.EventEmitter.emit (domain.js:471:20)
at TCP.<anonymous> (net.js:586:12)
My code is executing a multi command like this:
redisClient
.multi()
.expire(key, this.expire)
.hgetall(key)
.exec()
.then(
async ([[expErr, expVal], [hashErr, hashVal]]) => {
if (expErr || hashErr) {
throw expErr || hashErr;
}
return Object.values(hashVal);
},
)
.then(x => cb(null, x))
.catch(err => cb(err, []));
I believe this is the relevant debug output preceding the throw:
ioredis:redis status[127.0.0.1:7000]: [empty] -> wait +5ms
ioredis:delayqueue send 1 commands in failover queue +119ms
ioredis:redis status[127.0.0.1:7000]: wait -> connecting +1ms
ioredis:redis queue command[127.0.0.1:7000]: 0 -> multi([]) +1ms
ioredis:redis queue command[127.0.0.1:7000]: 0 -> expire([ 'mykey', '2592000' ]) +0ms
ioredis:redis queue command[127.0.0.1:7000]: 0 -> hgetall([ 'mykey' ]) +0ms
ioredis:redis queue command[127.0.0.1:7000]: 0 -> exec([]) +1ms
ioredis:connection error: Error: connect ECONNREFUSED 127.0.0.1:7000
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1054:14) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 7000
} +9ms
ioredis:redis status[127.0.0.1:7000]: connecting -> close +2ms
ioredis:connection skip reconnecting because `retryStrategy` is not a function +1ms
ioredis:redis status[127.0.0.1:7000]: close -> end +0ms
The promise for exec
does reject as expected (json taken from my log):
{
"type": "Error",
"message": "Connection is closed.",
"stack": "Error: Connection is closed.\n at close (/home/node/app/node_modules/ioredis/built/redis/event_handler.js:102:25)\n at Socket.<anonymous> (/home/node/app/node_modules/ioredis/built/redis/event_handler.js:73:20)\n at Object.onceWrapper (events.js:288:20)\n at Socket.emit (events.js:200:13)\n at Socket.EventEmitter.emit (domain.js:471:20)\n at TCP.<anonymous> (net.js:586:12)",
"previousErrors": [
{
"previousErrors": "[Circular]"
},
{
"previousErrors": "[Circular]"
},
{
"previousErrors": "[Circular]"
}
]
}
Is there something I can do to catch the rejection?
Possibly related, the 'error'
event listener I have attached to the cluster does not trigger when this happens, which also seems unexpected.
I was using 4.9.0
and tried updating to 4.9.5
, and have the same experience with both versions.
TIA for any guidance!
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
UnhandledPromiseRejectionWar...
UnhandledPromiseRejectionWarning : Error: Unable to get browser page #323 ... const cluster = await Cluster.launch({ concurrency: Cluster.
Read more >UnhandledPromiseRejectionWar...
UnhandledPromiseRejectionWarning : Unhandled promise rejection error I am getting I am using Node JS and mongo Db.
Read more >Connection issue with the cluster - MongoDB Atlas
When I use the cluster connection in the node getting unable to get data. UnhandledPromiseRejectionWarning: MongooseError: Operation `users.
Read more >Frequent Unknown failures with Unhandled Promise ...
Looking through my logs last night and noticed that I am seeing quite a bit of sub workflows failing due to unknown reason....
Read more >Couchbase server connection issue on 11210 port - Error
... (D:API\node_modules\ottoman\node_modules\couchbase\lib\cluster.js:612:14) (node:19964) UnhandledPromiseRejectionWarning: Unhandled ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for providing the minimal reproduction, it’ve been a great help. I created a pr to solve the issue: https://github.com/luin/ioredis/pull/884. Still writing tests for it.
This is error we are getting
0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.768Z ioredis:connection error: Error: connect ETIMEDOUT 0|main | 2019-06-28 17:24:13 +05:30: Error Error: connect ETIMEDOUT 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.768Z ioredis:redis status[localhost:6379]: connecting -> close 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.769Z ioredis:connection reconnect in 50ms 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.769Z ioredis:redis status[localhost:6379]: close -> reconnecting 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.769Z ioredis:connection error: Error: connect ETIMEDOUT 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.770Z ioredis:redis status[localhost:6379]: connecting -> close 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.770Z ioredis:connection skip reconnecting since the connection is manually closed. 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.770Z ioredis:redis status[localhost:6379]: close -> end 0|main | 2019-06-28 17:24:13 +05:30: errror: Error: Connection is closed. 0|main | at close (/nodeApi/node_modules/ioredis/built/redis/event_handler.js:109:25) 0|main | at Socket.<anonymous> (/nodeApi/node_modules/ioredis/built/redis/event_handler.js:76:20) 0|main | at Object.onceWrapper (events.js:277:13) 0|main | at Socket.emit (events.js:189:13) 0|main | at Socket.EventEmitter.emit (domain.js:441:20) 0|main | at TCP._handle.close (net.js:600:12) 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.780Z ioredis:connection error: Error: connect ETIMEDOUT 0|main | 2019-06-28 17:24:13 +05:30: Error Error: connect ETIMEDOUT 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.784Z ioredis:redis status[localhost:6379]: connecting -> close 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.784Z ioredis:connection reconnect in 50ms 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.785Z ioredis:redis status[localhost:6379]: close -> reconnecting 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.805Z ioredis:connection error: Error: connect ETIMEDOUT 0|main | 2019-06-28 17:24:13 +05:30: [ioredis] Unhandled error event: Error: connect ETIMEDOUT 0|main | at Socket.<anonymous> (/nodeApi/node_modules/ioredis/built/redis/index.js:270:31) 0|main | at Object.onceWrapper (events.js:277:13) 0|main | at Socket.emit (events.js:189:13) 0|main | at Socket.EventEmitter.emit (domain.js:441:20) 0|main | at Socket._onTimeout (net.js:443:8) 0|main | at ontimeout (timers.js:436:11) 0|main | at tryOnTimeout (timers.js:300:5) 0|main | at listOnTimeout (timers.js:263:5) 0|main | at Timer.processTimers (timers.js:223:10) 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.806Z ioredis:redis status[localhost:6379]: connecting -> close 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28T11:54:13.806Z ioredis:connection reconnect in 50ms 0|main | 2019-06-28 17:24:13 +05:30: 2019-06-28