Skip to content
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
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ function fastifyRedis (fastify, options, next) {
onEnd(err)
return
}
if (err.code === 'SELF_SIGNED_CERT_IN_CHAIN') {
// This error is not recoverable because ioredis will never be able to connect to the server unless the user changes the TLS options.
onEnd(err)
return
}

// Swallow network errors to allow ioredis
// to perform reconnection and emit 'end'
Expand Down
30 changes: 30 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,36 @@ test('catch .ping() errors', async (t) => {
await t.assert.rejects(fastify.ready(), new Redis.ReplyError('ping error'))
})

test('Should propagate SELF_SIGNED_CERT_IN_CHAIN error', async (t) => {
t.plan(1)

const fastify = Fastify()
t.after(() => fastify.close())

const fastifyRedis = proxyquire('..', {
ioredis: function Redis () {
this.ping = () => {
const error = new Error('self signed certificate in certificate chain')
error.code = 'SELF_SIGNED_CERT_IN_CHAIN'
return Promise.reject(error)
}
this.quit = () => {}
this.info = cb => cb(null, 'info')
this.on = function () {
return this
}
this.off = function () { return this }

return this
}
})
fastify.register(fastifyRedis)

const error = new Error('self signed certificate in certificate chain')
error.code = 'SELF_SIGNED_CERT_IN_CHAIN'
await t.assert.rejects(fastify.ready(), error)
})

setInterval(() => {
whyIsNodeRunning()
}, 5000).unref()