jeremydaly / serverless-mysql

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

PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR #133

Closed kamalnathlp closed 1 year ago

kamalnathlp commented 2 years ago

We are getting the PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR issue, i have checked the mysql active connections, it is used below 10%. But still we are getting the issue.

marcos-arata commented 1 year ago

@kamalnathlp did you mange to solve this? I'm getting the same behavior here

naorpeled commented 1 year ago

Looking into this 👀

naorpeled commented 1 year ago

@kamalnathlp did you mange to solve this? I'm getting the same behavior here

Hey @marcos-instaviagem can you try to install https://github.com/jeremydaly/serverless-mysql/tree/resolve-fatal-error in your package json and see if my change fixed your issue?

Also, can you specify your configuration so I can try and re-produce this issue using the same one?

marcos-arata commented 1 year ago

@naorpeled I installed this branch on a test env here, I'll check the results and reply to you asap

i'm working on cloud functions (nodejs16) + mysql, the log of the error that I receive is this:

Error: Cannot enqueue Query after fatal error.
    at Protocol._validateEnqueue (/workspace/node_modules/mysql/lib/protocol/Protocol.js:212:16)
    at Protocol._enqueue (/workspace/node_modules/mysql/lib/protocol/Protocol.js:138:13)
    at Connection.query (/workspace/node_modules/mysql/lib/Connection.js:198:25)
    at /workspace/index.js:322:22
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

not 100% sure, but it appears that if any error occurs on the instance and the next execution (on the same instance) uses serverless-mysql, then the query is not executed and it throws this error. therefore, the query will only work when this instance is shut down and a new healthy one is up, all queries will crash during this period

naorpeled commented 1 year ago

@naorpeled I installed this branch on a test env here, I'll check the results and reply to you asap

i'm working on cloud functions (nodejs16) + mysql, the log of the error that I receive is this:

Error: Cannot enqueue Query after fatal error.
    at Protocol._validateEnqueue (/workspace/node_modules/mysql/lib/protocol/Protocol.js:212:16)
    at Protocol._enqueue (/workspace/node_modules/mysql/lib/protocol/Protocol.js:138:13)
    at Connection.query (/workspace/node_modules/mysql/lib/Connection.js:198:25)
    at /workspace/index.js:322:22
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

not 100% sure, but it appears that if any error occurs on the instance and the next execution (on the same instance) uses serverless-mysql, then the query is not executed and it throws this error

Hmmm, I see. Will aim to take a look at this sometime the next few days.

Will keep you posted

marcos-arata commented 1 year ago

ok, so I monitored my function for a couple of hours and it looks like it solved this issue after I deployed this branch!

marcos-arata commented 1 year ago

while checking logs of other functions I noticed that I also received this kind of error as well. do you know if this could be a similar type of error?

Error: ER_LOCK_WAIT_TIMEOUT: Lock wait timeout exceeded; try restarting transaction
    at Query.Sequence._packetToError (/workspace/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
    at Query.ErrorPacket (/workspace/node_modules/mysql/lib/protocol/sequences/Query.js:79:18)
    at Protocol._parsePacket (/workspace/node_modules/mysql/lib/protocol/Protocol.js:291:23)
    at Parser._parsePacket (/workspace/node_modules/mysql/lib/protocol/Parser.js:433:10)
    at Parser.write (/workspace/node_modules/mysql/lib/protocol/Parser.js:43:10)
    at Protocol.write (/workspace/node_modules/mysql/lib/protocol/Protocol.js:38:16)
    at Socket.<anonymous> (/workspace/node_modules/mysql/lib/Connection.js:88:28)
    at Socket.<anonymous> (/workspace/node_modules/mysql/lib/Connection.js:523:10)
    at Socket.emit (events.js:198:13)
    at Socket.EventEmitter.emit (domain.js:466:23)
naorpeled commented 1 year ago

while checking logs of other functions I noticed that I also received this kind of error as well. do you know if this could be a similar type of error?

Error: ER_LOCK_WAIT_TIMEOUT: Lock wait timeout exceeded; try restarting transaction
    at Query.Sequence._packetToError (/workspace/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
    at Query.ErrorPacket (/workspace/node_modules/mysql/lib/protocol/sequences/Query.js:79:18)
    at Protocol._parsePacket (/workspace/node_modules/mysql/lib/protocol/Protocol.js:291:23)
    at Parser._parsePacket (/workspace/node_modules/mysql/lib/protocol/Parser.js:433:10)
    at Parser.write (/workspace/node_modules/mysql/lib/protocol/Parser.js:43:10)
    at Protocol.write (/workspace/node_modules/mysql/lib/protocol/Protocol.js:38:16)
    at Socket.<anonymous> (/workspace/node_modules/mysql/lib/Connection.js:88:28)
    at Socket.<anonymous> (/workspace/node_modules/mysql/lib/Connection.js:523:10)
    at Socket.emit (events.js:198:13)
    at Socket.EventEmitter.emit (domain.js:466:23)

I think that this is a bit different because this is something that seems more related to transactions and not initiating a connection. My guess is that we'd need to change something else in the lib's implementation to make this work.

I'll aim to take a further look at this in one of the next few days if that's alright.

marcos-arata commented 1 year ago

sure, no problem! thanks for your support

On this case is a unique query with a multipleStatements model: a combined select and then an update query. Most of the time it works, but sometimes returns this mentioned error before.

connection_serverless.query(`SELECT * FROM table WHERE id = ?; 
                                                    UPDATE table SET field=? WHERE id = ?; `,

Should it be transformed into a transaction model instead (separated queries) in order to reduce errors?

naorpeled commented 1 year ago

sure, no problem! thanks for your support

On this case is a unique query with a multipleStatements model: a combined select and then an update query. Most of the time it works, but sometimes returns this mentioned error before.

connection_serverless.query(`SELECT * FROM table WHERE id = ?; 
                                                    UPDATE table SET field=? WHERE id = ?; `,

Should it be transformed into a transaction model instead (separated queries) in order to reduce errors?

Hmm, I think the error is more related to a non rollbacked/committed transaction, and not this specific query, so I'd make sure that all transactions are properly closed.

naorpeled commented 1 year ago

Hey, i'm closing this issue as completed for now. Feel free to ping me if you need anything else.

marcos-arata commented 1 year ago

should I keep using that branch tree or did you merge it into a release? thanks

naorpeled commented 1 year ago

should I keep using that branch tree or did you merge it into a release? thanks

Hey, I haven't merged the change yet, need to do a bit more investigation. Will get to it in few days and ping you when I reach a conclusion. I hope that's okay