Received packet in the wrong sequence

Hi,
*I was using a lambda function to connect to MySQL database code here

var connection = mysql.createConnection({
          host : "remotemysql.com",
          user: "",
          database: "",
          password: ""
          //port:"3306"
        });
    }

exports.handler = function (event, context, callback) {
    context.callbackWaitsForEmptyEventLoop =false;
    connection.connect(function(err) {
      if (err) {
        console.error('Error connecting: ' + err.stack);
      }
      console.log('Connected as thread id: ' + connection.threadId);
    });

var results=[];
//SQL Query > Select Data

return new Promise((resolve, reject) => {
  const readTable = `SELECT * FROM num_of_likes`;
  connection.query(readTable, (err, results, fields) => {
    if (err) {
     reject(err);
    } else {
      resolve({statusCode: 200, body: {results}});
    }
  });
});

*Lambda server is listening on 9000
Request from ::1: GET /connect
Error connecting: Error: Received packet in the wrong sequence.
at A._parsePacket (/Users/riteshkarwa/netlify/functions/connect.js:1:93387)
at A._parsePacket (/Users/riteshkarwa/netlify/functions/connect.js:1:102113)
at A.write (/Users/riteshkarwa/netlify/functions/connect.js:1:96341)
at A.write (/Users/riteshkarwa/netlify/functions/connect.js:1:89855)
at Socket. (/Users/riteshkarwa/netlify/functions/connect.js:1:7771)
at Socket. (/Users/riteshkarwa/netlify/functions/connect.js:1:6835)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:182:23)
--------------------
at A._enqueue (/Users/riteshkarwa/netlify/functions/connect.js:1:91233)
at A.handshake (/Users/riteshkarwa/netlify/functions/connect.js:1:89978)
at o.connect (/Users/riteshkarwa/netlify/functions/connect.js:1:8643)
at Object.E.handler (/Users/riteshkarwa/netlify/functions/connect.js:1:238235)
at /Users/riteshkarwa/netlify/node_modules/netlify-lambda/lib/serve.js:144:27
at Layer.handle [as handle_request] (/Users/riteshkarwa/netlify/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:137:13)
at next (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:131:14)
at next (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:131:14)
at next (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:131:14)
at next (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:131:14)
at next (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:131:14)
at next (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:131:14)
at Route.dispatch (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/riteshkarwa/netlify/node_modules/express/lib/router/layer.js:95:5)
at /Users/riteshkarwa/netlify/node_modules/express/lib/router/index.js:281:22
Connected as thread id: 15223054
Response with status 500 in 2105 ms.
Error during invocation: Error: Received packet in the wrong sequence.
at A._parsePacket (/Users/riteshkarwa/netlify/functions/connect.js:1:93387)
at A._parsePacket (/Users/riteshkarwa/netlify/functions/connect.js:1:102113)
at A.write (/Users/riteshkarwa/netlify/functions/connect.js:1:96341)
at A.write (/Users/riteshkarwa/netlify/functions/connect.js:1:89855)
at Socket. (/Users/riteshkarwa/netlify/functions/connect.js:1:7771)
at Socket. (/Users/riteshkarwa/netlify/functions/connect.js:1:6835)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:182:23)
--------------------
at A._enqueue (/Users/riteshkarwa/netlify/functions/connect.js:1:91233)
at A.handshake (/Users/riteshkarwa/netlify/functions/connect.js:1:89978)
at o.connect (/Users/riteshkarwa/netlify/functions/connect.js:1:8643)
at Object.E.handler (/Users/riteshkarwa/netlify/functions/connect.js:1:238235)
at /Users/riteshkarwa/netlify/node_modules/netlify-lambda/lib/serve.js:144:27
at Layer.handle [as handle_request] (/Users/riteshkarwa/netlify/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:137:13)
at next (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:131:14)
at next (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:131:14)
at next (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:131:14)
at next (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:131:14)
at next (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:131:14)
at next (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:131:14)
at Route.dispatch (/Users/riteshkarwa/netlify/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/riteshkarwa/netlify/node_modules/express/lib/router/layer.js:95:5)
at /Users/riteshkarwa/netlify/node_modules/express/lib/router/index.js:281:22 {
code: ‘PROTOCOL_INCORRECT_PACKET_SEQUENCE’,
fatal: true
}

so far I did not find a way to solve it by search google

Hi @ritesh, are you bundling your function? if so, try without bundling and se if it works for you.

hi @futuregerald , as far as I know I have not bundled the function, I just created connect.js which has the logic to connect to MySQL database. So i went ahead and disabled everything in asset optimization setting.
I am just experimenting, I don’t think I am doing it right.

Error messages i got after deploy and hitting https://southernsunshineandroses.netlify.com/.netlify/functions/connect
{"errorMessage":"Received packet in the wrong sequence.","errorType":"Error","stackTrace":["s._parsePacket (/var/task/connect.js:1:106224)","s._parsePacket (/var/task/connect.js:1:114950)","s.write (/var/task/connect.js:1:109178)","s.write (/var/task/connect.js:1:102692)","Socket.<anonymous> (/var/task/connect.js:1:9937)","Socket.<anonymous> (/var/task/connect.js:1:9001)","emitOne (events.js:116:13)","Socket.emit (events.js:211:7)","addChunk (_stream_readable.js:263:12)","readableAddChunk (_stream_readable.js:250:11)"," --------------------","s._enqueue (/var/task/connect.js:1:104070)","s.handshake (/var/task/connect.js:1:102815)","T.connect (/var/task/connect.js:1:10809)","e.handler (/var/task/connect.js:8:18859)"]}

OK, and this function works locally when run with netlify-lambda serve ?

Hi @fool , it does not work locally as well same error

ah, ok. That is extremely useful information to tell us up front in the future, please!

Our stiff can’t help consult about your code not working; just about working code that doesn’t work on netlify :slight_smile:

Other community members may have more advice for you though they may not too…