microlinkhq/keyvhq

[@keyvhq/mysql] Can't add new command when connection is in closed state

supercrafter100 opened this issue · 3 comments

Issue

I've been getting this error lately after trying to perform an action with the database when the connection hasn't been touched in some time. It seems like it just gets disconnected and doesn't attempt to reconnect automatically. Is this functionality I should implement on my own side?

Error

Error: Can't add new command when connection is in closed state
    at PromiseConnection.execute (/home/container/node_modules/mysql2/promise.js:111:22)
    at /home/container/node_modules/@keyvhq/mysql/src/index.js:30:36
    at /home/container/node_modules/@keyvhq/sql/src/index.js:47:55
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Keyv.get (/home/container/node_modules/@keyvhq/core/src/index.js:62:17) {
  code: undefined,
  errno: undefined,
  sql: undefined,
  sqlState: undefined,
  sqlMessage: undefined
}

Relevant code

const url = `mysql://${process.env.DB_USER}:${process.env.DB_PASS}@${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.DB_NAME}`;
const keyv = new Keyv({
    store: new KeyvSQL(url, {
        table: "guilds",
    })
});

Seems to be related to sidorares/node-mysql2#939, will test out the suggested solution.
How long does it take for it to get disconnected ?

I haven't timed it really. I know for sure that after a day of the connection not doing anything this for sure happens. But it could be that it happens quicker. Would have to perform some testing to get an accurate answer to that

Please reopen if the issue persists