Skip to content

Commit

Permalink
fix crash if redis disconnects (#3954)
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi committed Aug 4, 2022
1 parent 5b491f7 commit 88b08e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/@uppy/companion/src/server/emitter/redis-emitter.js
@@ -1,6 +1,8 @@
const redis = require('redis')
const { EventEmitter } = require('node:events')

const logger = require('../logger')

/**
* This module simulates the builtin events.EventEmitter but with the use of redis.
* This is useful for when companion is running on multiple instances and events need
Expand All @@ -10,10 +12,12 @@ module.exports = (redisUrl, redisPubSubScope) => {
const prefix = redisPubSubScope ? `${redisPubSubScope}:` : ''
const getPrefixedEventName = (eventName) => `${prefix}${eventName}`
const publisher = redis.createClient({ url: redisUrl })
publisher.on('error', err => logger.error('publisher redis error', err))
let subscriber

const connectedPromise = publisher.connect().then(() => {
subscriber = publisher.duplicate()
subscriber.on('error', err => logger.error('subscriber redis error', err))
return subscriber.connect()
})

Expand Down
2 changes: 2 additions & 0 deletions packages/@uppy/companion/src/server/redis.js
Expand Up @@ -15,6 +15,8 @@ function createClient (opts) {
// todo remove legacyMode when fixed: https://github.com/tj/connect-redis/issues/361
redisClient = redis.createClient({ ...opts, legacyMode: true })

redisClient.on('error', err => logger.error('redis error', err))

;(async () => {
try {
// fire and forget.
Expand Down

0 comments on commit 88b08e3

Please sign in to comment.