0
node:events:492 Uncaught Error: read ECONNRESET
    at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
    at __node_internal_errnoException (node:internal/errors:623:12)
    at TCP.onStreamRead (node:internal/stream_base_commons:217:20)

what causing this problem as after connecting to the mysql database this error pops up on the console on its own.

2

1 Answer 1

1

First of all, you should catch the error, so you app can handle it properly and doesn't crash when mysql connection is closed for any odd reason. Try either with connection.on('error', ...) or with try-catch blocks.

For keeping an open connection, you should either reconnect on close. Or simply use mysql's pooling connection, which handles automatic reconnection very well, with a single code change.

PS: Pooling multiple connections is a generally good idea for async apps, like servers, but it's safe to maintain a single connection via pooling (connectionLimit : 1) just for automatic reconnection itself.

PPS: Mysql's inactivity timeout can be configured in server's my.cnf

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.