Reputation: 5944
I am facing a strange issue on AWS Lambda in which my API calls fail with a 502 error,
I checked the CloudWatch logs, and in these cases, not even my 1st line of code which is logging the event object is getting printed
The function call is not reaching the DAO layer of my code for sure.
The logs are showing the following trace -
2019-07-25T08:03:55.668Z 2329a426-a841-4ce2-91ed-1000c623ba14 Error: Quit inactivity timeout
at Quit.<anonymous> (/opt/layer/node_modules/mysql/lib/protocol/Protocol.js:160:17)
at emitNone (events.js:106:13)
at Quit.emit (events.js:208:7)
at Quit._onTimeout (/opt/layer/node_modules/mysql/lib/protocol/sequences/Sequence.js:124:8)
at Timer._onTimeout (/opt/layer/node_modules/mysql/lib/protocol/Timer.js:32:23)
at ontimeout (timers.js:482:11)
at tryOnTimeout (timers.js:317:5)
at Timer.listOnTimeout (timers.js:277:5)
Here's a log sample of this strange request -
I this API behavior is inconsistent,
These failure calls don't even print the first line of my handler
I am using node 8.10
and mysql lib "mysql": "^2.17.1"
Upvotes: 1
Views: 3165
Reputation: 51
how are you?
I was facing the same problem and I solved it very simply:
I changed the connection.end (); by connectionn.destroy ();
The destroy, after performing its function, immediately terminates the connection with the DB. the "end" is asynchronous and this can be the cause of the error.
Look:
"To force the connection close immediately, you can use the destroy() method. The destroy() method guarantees that no more callbacks or events will be triggered for the connection. Note that the destroy() method does not take any callback argument like the end() method."
Font:https://www.mysqltutorial.org/mysql-nodejs/connect/
Upvotes: 5