Getting fatal error while connecting node.js with mysql

Not applicable

Error:

{"fault":{"faultstring":"Script execution failed: Cannot enqueue Query after fatal error.: Error: Cannot enqueue Query after fatal error.\n at \/organization\/environment\/api\/getempdata.js:15\n at domain.js:183\n at \/organization\/environment\/api\/node_modules\/mysql\/lib\/protocol\/sequences\/Sequence.js:96\n at \/organization\/environment\/api\/node_modules\/mysql\/lib\/protocol\/Protocol.js:226\n at _tickDomainCallback (trireme.js:491)\n at _tickFromSpinner (trireme.js:422)\n","detail":{"errorcode":"scripts.node.runtime.ScriptExecutionError"}}}

Every morning when i try to hit the url i get this error. Once I re-save the proxy i get the expected output.

How to solve this error?

Because everyday its not possible to save proxy and then get the output

0 2 4,608
2 REPLIES 2

Hi @Riddhi Thacker, it is difficult to provide any useful answer without seeing what code you have that is causing this issue.

Understanding how the node runtime on edge behaves might help you.

In Edge, when the proxy is first deployed, the node application is started and this then keeps running until the proxy is next redeployed. It is quite possible that you are creating the connections to mysql when the node application is loaded.

Probably after a while the connection is dropped due to inactivity and hence when you make a new API call after a long gap, you are getting this error.

To use this right it will be best if you create the connection whenever an API request is made i.e. maybe in the GET handler of your http / express module. This way a new connection will be created for every request and the connection can be dropped after returning the response.

Also, it will be a good idea to isolate the cause of the error by running the node code(s) in your desktop on a standalone node.js server. Leave it running there for a day or 2 and then make a call to the node app to see if you get the same error, or whether the error occurs only on the edge platform.

Do you have still have this issue? There are a few suggestions to troubleshoot this further - https://github.com/mysqljs/mysql/issues/832