#2396·mysql

Disconnecting while there is an "active query" stream exits the node process abruptly

Author: yonguelinkCreated Aug 26, 2020Updated Mar 13, 2022
Labelsneeds investigation

With an active connection, starting a query in stream mode and calling connection.end() abruptly exit nodes with no error code.

Reproducing the problem

  1. Clone the example project we created here: https://github.com/pmctire/mysql-abrupt-exit
  2. Install Docker if you don't really have it to be able to run docker-compose - https://docs.docker.com/compose/install/
  3. Follow the instructions in the README of the project

The base logic of the example project is:

  1. Connect to a database
  2. Start a query in stream mode (connection.query(...).stream())
  3. Disconnect from the database
  4. Notice how anything after the disconnect wasn'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.