Disconnecting while there is an "active query" stream exits the node process abruptly
With an active connection, starting a query in stream mode and calling connection.end() abruptly exit nodes with no error code.
Reproducing the problem
- Clone the example project we created here: https://github.com/pmctire/mysql-abrupt-exit
- Install Docker if you don't really have it to be able to run
docker-compose- https://docs.docker.com/compose/install/ - Follow the instructions in the README of the project
The base logic of the example project is:
- Connect to a database
- Start a query in stream mode (
connection.query(...).stream()) - Disconnect from the database
- Notice how anything after the
disconnectwasn't executed
This can be seen in the main of the example: https://github.com/pmctire/mysql-abrupt-exit/blob/master/mysql-early-exit.js#L55
Example behaviour
Problematic behaviour
When running the example with --no-process-results argument, you will NOT see the Disconnected, THIS IS NEVER SHOWN message. It seems like something is calling exit(0) behind the scene when there is an "active query" in stream mode left unattended.
"Normal" behaviour
When running the example with --process-results you'll get the Disconnected, THIS IS NEVER SHOWN message printed. This is because we're ensuring the stream ends. The same behaviour can be experienced WITHOUT ensuring the end of the stream, but by simply connecting it to something that will eventually consume it, i.e.: as long as something will consumes the stream, you can call connection.end() without any issue.
Expected behaviour
We expect connection.end() to NOT abruptly exit node OR to crash the process with an error message.
Source: mysqljs/mysql