jeremydaly / serverless-mysql

A module for managing MySQL connections at SERVERLESS scale
MIT License
1.21k stars 83 forks source link

Received packet in the wrong sequence #158

Closed davidnewcomb closed 5 months ago

davidnewcomb commented 6 months ago

I have used serverless-mysql in a NextJs node project. When I make a production build I get

exception to sql query : ****** Error Received packet in the wrong sequence.
    at W (/Users/mrn/myproj/.next/server/chunks/5450.js:8:1147)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.k [as query] (/Users/mrn/myproj/.next/server/chunks/5450.js:8:1591)
    at async n (/Users/mrn/myproj/.next/server/chunks/1871.js:1:10953)
    at async c (/Users/mrn/myproj/.next/server/app/api/rating/route.js:1:1617)
    at async g (/Users/mrn/myproj/.next/server/app/api/rating/route.js:1:2241)
    at async /Users/mrn/myproj/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:34666
    at async eS.execute (/Users/mrn/myproj/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:25813)
    at async eS.handle (/Users/mrn/myproj/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:35920)
    at async doRender (/Users/mrn/myproj/node_modules/next/dist/server/base-server.js:1377:42)

Apparently this is because serverless-mysql uses mysql which mangles some important names. The current recomendation is to switch to using mysql2 instead.

Are mysql and mysql2 compactable from your side?

More information here: https://stackoverflow.com/a/55990035/52070

naorpeled commented 6 months ago

Hey @davidnewcomb, specifying the following in your serverless-mysql config object should do the trick.

{
    ///...
    library: require('mysql2')
}
MainJ0SHK1 commented 5 months ago

@naorpeled, Perhaps I'm late, but I have done the same thing but to no Avail. I'm still getting the very same error. Perhaps I'm doing something wrong?


import mysql from "serverless-mysql";

export const DB = mysql({
  config: {
    host: process.env.MYSQL_HOST,
    database: process.env.MYSQL_DATABASE,
    user: process.env.MYSQL_USER,
    password: process.env.MYSQL_PASSWORD,
    library: require("mysql2"),
  },
});
naorpeled commented 5 months ago

@naorpeled, Perhaps I'm late, but I have done the same thing but to no Avail. I'm still getting the very same error. Perhaps I'm doing something wrong?


import mysql from "serverless-mysql";

export const DB = mysql({
  config: {
    host: process.env.MYSQL_HOST,
    database: process.env.MYSQL_DATABASE,
    user: process.env.MYSQL_USER,
    password: process.env.MYSQL_PASSWORD,
    library: require("mysql2"),
  },
});

Try to import using the same syntax that you imported serverless-mysql with. Let me know if that helps 🙏

alexander-williamson commented 5 months ago

@MainJ0SHK1 do you not need to configure it outside of the config block?

import mysql from "serverless-mysql";

export const DB = mysql({
  config: {
    host: process.env.MYSQL_HOST,
    database: process.env.MYSQL_DATABASE,
    user: process.env.MYSQL_USER,
    password: process.env.MYSQL_PASSWORD
  },
  library: require("mysql2") // lives here
});

https://github.com/jeremydaly/serverless-mysql/blob/5c23404b92777c4fae151ec214c2514fa4af8bf9/README.md?plain=1#L152

MainJ0SHK1 commented 5 months ago

@alexander-williamson, you were correct about that. I thought I had done that already, but perhaps i hadn't done it correctly. It seems to be working now. I appreciate it!