tediousjs/tedious-connection-pool

Draining the pool after releasing connections may cause write to destroyed stream

irgijs opened this issue · 3 comments

Using

pool.release();
pool.drain();

May (not necessarily) result in the error below
Connection lost - Cannot call write after a stream was destroyed

The pool.release methods calls the connection.reset method. This methods executes SQL queries to reset to the initial state of the connection. pool.release does not use promises, so pool.drain in the above example is immediately called afterwards. pool.drain closes the connections. If one of these connections still have a request connection pending (or any other request!) it results in the above mentioned error.

I will provide a PR containing a fix soon.

Pull Request: #59

nul commented

Is there any update on this?

@nul The PR was an example fix for this problem, it's up to the maintainer of this repo if our example should be used to fix this. (But the example I provided does work, so I suggest to fork this repo and apply the fix yourself using the PR since this repository is not actively maintained anymore)