Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long running connection getting dropped without proper handling #53

Open
ghost opened this issue Dec 19, 2018 · 1 comment
Open

Long running connection getting dropped without proper handling #53

ghost opened this issue Dec 19, 2018 · 1 comment

Comments

@ghost
Copy link

ghost commented Dec 19, 2018

I have an express server, responding to API calls.

Before calling server.listen() I initialise the Query Builder, and leave it running in the background

It all works fine until after an arbitrary amount of time passes and I get this

events.js:167
      throw er; // Unhandled 'error' event
      ^
Error: Connection lost: The server closed the connection.
    at Protocol.end (/data/darends/artron/backend/node_modules/mysql/lib/protocol/Protocol.js:112:13)
    at Socket.<anonymous> (/data/darends/artron/backend/node_modules/mysql/lib/Connection.js:97:28)
    at Socket.<anonymous> (/data/darends/artron/backend/node_modules/mysql/lib/Connection.js:502:10)
    at Socket.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1094:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
    at Connection._handleProtocolError (/data/darends/artron/backend/node_modules/mysql/lib/Connection.js:425:8)
    at Protocol.emit (events.js:182:13)
    at Protocol._delegateError (/data/darends/artron/backend/node_modules/mysql/lib/protocol/Protocol.js:390:10)
    at Protocol.end (/data/darends/artron/backend/node_modules/mysql/lib/protocol/Protocol.js:116:8)
    at Socket.<anonymous> (/data/darends/artron/backend/node_modules/mysql/lib/Connection.js:97:28)
    [... lines matching original stack trace ...]
    at process._tickCallback (internal/process/next_tick.js:63:19)

Note: This occurs when using single or pool (even with qb.release())

On researching how mysqljs/mysql handles its fatal errors,

If a fatal errors occurs and there are no pending callbacks, or a normal error occurs which has no callback belonging to it, the error is emitted as an 'error' event on the connection object. This is demonstrated in the example below:

Query Builder does not expose anything which would allow me to either catch or handle the error

mysql suggests this method.

connection.on('error', function(err) {
  console.log(err.code); // 'ER_BAD_DB_ERROR'
});

I was wondering if either

  • this .on method is able to be exposed
  • in the config, pass a callback which is automatically attached this listener
@rohit-gh
Copy link

rohit-gh commented Sep 27, 2020

@kylefarris
I'm facing this error as well, any updates on this?
can we have a error handler API exposed like :

let qb = pool.get_connection();
 qb.on('error', async (err) => {
   // handle errors.
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant