Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Connection is closed. for shared connection #1218

Closed
cnwangjie opened this issue Apr 27, 2022 · 4 comments
Closed

Error: Connection is closed. for shared connection #1218

cnwangjie opened this issue Apr 27, 2022 · 4 comments

Comments

@cnwangjie
Copy link

I got this error if I use redis.quit to close the connection instead of queue.close.

    Error: Unhandled error. (Error: Connection is closed.
        at EventEmitter.sendCommand (/Users/wangjie/Workspace/troph-team/chat-server-boilerplate/node_modules/ioredis/built/Redis.js:315:28)
        at EventEmitter.info (/Users/wangjie/Workspace/troph-team/chat-server-boilerplate/node_modules/ioredis/built/utils/Commander.js:90:25)
        at RedisConnection.getRedisVersion (/Users/wangjie/Workspace/troph-team/chat-server-boilerplate/node_modules/bullmq/src/classes/redis-connection.ts:209:36)
        at RedisConnection.init (/Users/wangjie/Workspace/troph-team/chat-server-boilerplate/node_modules/bullmq/src/classes/redis-connection.ts:152:33))
        at new NodeError (node:internal/errors:371:5)
        at Queue.emit (node:events:379:17)
        at Queue.emit (/Users/wangjie/Workspace/troph-team/chat-server-boilerplate/node_modules/bullmq/src/classes/queue-base.ts:53:20)
        at Queue.emit (/Users/wangjie/Workspace/troph-team/chat-server-boilerplate/node_modules/bullmq/src/classes/queue.ts:135:18)
        at RedisConnection.emit (node:events:390:28)
        at /Users/wangjie/Workspace/troph-team/chat-server-boilerplate/node_modules/bullmq/src/classes/redis-connection.ts:70:41 {
      code: 'ERR_UNHANDLED_ERROR',
      context: Error: Connection is closed.
          at EventEmitter.sendCommand (/Users/wangjie/Workspace/troph-team/chat-server-boilerplate/node_modules/ioredis/built/Redis.js:315:28)
          at EventEmitter.info (/Users/wangjie/Workspace/troph-team/chat-server-boilerplate/node_modules/ioredis/built/utils/Commander.js:90:25)
          at RedisConnection.getRedisVersion (/Users/wangjie/Workspace/troph-team/chat-server-boilerplate/node_modules/bullmq/src/classes/redis-connection.ts:209:36)
          at RedisConnection.init (/Users/wangjie/Workspace/troph-team/chat-server-boilerplate/node_modules/bullmq/src/classes/redis-connection.ts:152:33)
    }

I found a similar issue for that (#670).

It seems fixed the problem with Worker but the Queue will still encounter this problem.

@manast
Copy link
Contributor

manast commented Apr 30, 2022

With Queue, since the connection is shared it cannot be avoided, if you close the connection then the Queue will fail. The solution is to not share the connection if you need to call quit on that given client.

@manast manast closed this as completed Apr 30, 2022
@JClackett
Copy link

Hi @manast, since 1.8.2, i'm also getting these on Heroku. Local development seems fine so maybe something with the Heroku redis version? im not calling redis.quit() or queue.close(). What's weird is that everything still works (I think) but just the logs keep showing up as below.

Error: Connection is closed.
at EventEmitter.emit (node:domain:475:12)
EventEmitter.RedisConnection.handleClientClose (/app/node_modules/bullmq/dist/cjs/classes/redis-connection.js:54:32)

Bit confused about the work Worker/Queue thing, but I am using it like this:

"bullmq": "1.81.2",
"ioredis": "5.0.4",
// redis
import Redis from "ioredis"
export const redis = new Redis(REDIS_URL, { maxRetriesPerRequest: null, enableReadyCheck: false })

// queue setup
export const WORKER_KEY = "TEST1"
new QueueScheduler(WORKER_KEY, { connection: redis })
export const userQueue = new Queue(WORKER_KEY, { connection: redis })

// somewhere
userQueue.add(
  // stuff
)

// worker processing
new Worker(
      WORKER_KEY,
      async (job: Jobs) => {
        // process stuff
      },
      { connection: redis },
    )

spot anything I could be doing wrong? I've got multiple queue's workers as well

@manast
Copy link
Contributor

manast commented May 5, 2022

Sorry I do not see anything in that code that would explain the log you posted above, particularly there are no calls to close or quit so it is strange. But definitely not related to Heroku's Redis version.

@MarcusHSmith
Copy link

We're experiencing a similar issue:

bullmq@1.82.2
ioredis@4.28.5
new IORedis(url, {
  enableReadyCheck: false,
  connectTimeout: 500,
  lazyConnect: true,
  maxRetriesPerRequest: 5,
  tls:
    {
          rejectUnauthorized: false,
        },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants