serverless-mysql icon indicating copy to clipboard operation
serverless-mysql copied to clipboard

Question: Socket closed error

Open jdchmiel opened this issue 5 years ago • 0 comments

I have a graphQl Lambda using serverless-mysql with mysql2. I am very rarely getting a lambda in a bad state where it cannot reconnect to the db. The sequence of errors is as follows:

ERROR { Error: This socket has been ended by the other party
at TLSSocket.writeAfterFIN [as write] (net.js:395:12)
INFO { [Error: Context creation failed: This socket has been ended by the other party]
message:
'Context creation failed: This socket has been ended by the other party',
locations: undefined,
path: undefined,
extensions:
{ code: 'INTERNAL_SERVER_ERROR',
exception: { stacktrace: [Array] } } }
ERROR { Error: Can't add new command when connection is in closed state

and then the INFO and ERROR repeat for each attempt from the browser to post to the Lambda in question.

In order to try and reproduce this, In some test code I have set the db timeout to 2 seconds and find it reconnects as expected. I have tried passing wrong user, but it fails immediately as expected and no further attempts on the connection occur with the thrown exception.

Has anyone else come across this closed socket issue and worked around it?

jdchmiel avatar Oct 02 '19 17:10 jdchmiel