ioredis icon indicating copy to clipboard operation
ioredis copied to clipboard

[email protected] redis.quit() met Error "Connection is closed."

Open leiwng opened this issue 2 years ago • 0 comments

Err Msg:

D:\Prj\voyager\melissokomos\node_modules\ioredis\built\redis\event_handler.js:182 self.flushQueue(new Error(utils_1.CONNECTION_CLOSED_ERROR_MSG)); ^

Error: Connection is closed. at close (D:\Prj\voyager\melissokomos\node_modules\ioredis\built\redis\event_handler.js:182:25) at Socket. (D:\Prj\voyager\melissokomos\node_modules\ioredis\built\redis\event_handler.js:149:20) at Object.onceWrapper (node:events:628:26) at Socket.emit (node:events:513:28) at TCP. (node:net:322:12)

Node.js v18.16.0

Related Code Segment:

const Redis = require("ioredis") ,,, class Cellar { this.redis = new Redis(this.redis_url) ... // Handle Ctrl+C process.on("SIGINT", () => {

  this.stop()

  logger.info(
    {
      node_id: this.node_id,
      node_type: this.node_type,
    },
    "Cellar Exit thru Ctrl+C pressed."
  )

  // process exit
  setTimeout(() => {
    process.exit(0)
  }, 1000)
})

... stop() { ... this.close_redis_safely(this.redis, this.redis_url) ... } ... close_redis_safely(redis_client, connection_url) { try { if (redis_client) {

    redis_client.quit()

    logger.info(
      {
        node_id: this.node_id,
        node_type: this.node_type,
        connection_url,
      },
      `Parser(Cellar) Node: ${this.node_id} Redis Disconnected.`
    )

  }
} catch (error) {
  logger.error(
    {
      node_id: this.node_id,
      node_type: this.node_type,
      connection_url,
      error
    },
    "Redis already Disconnected."
  )

} finally {
  // Release any other resources related to Redis, if applicable
  // do nothing
}

} ... } // end of Cellar

Comments

The cellar process will be exited after press Ctrl+C. And process.on will catch that event and invoke this.stop() to stop cellar instance. In the stop process, it will invoke redis_client.quit() to quit redis service. Then, the error came out.

found an old issue maybe related: https://github.com/redis/ioredis/issues/971

leiwng avatar Jul 13 '23 03:07 leiwng