mysql icon indicating copy to clipboard operation
mysql copied to clipboard

An unclosed client may cause Deno from exiting automatically

Open lideming opened this issue 5 years ago • 1 comments

A not closed client with idle connections will prevent Deno from automatically exiting, after implementing idle timeout (#81).

This is a problem, especially in short-running applications.

For example:

const client = new Client().connect(/* ... */);
console.log(await client.query("SELECT ..."));
// End of file, but Deno won't exit

Deno won't exit after it finishes querying, because there is some timer (by setTimeout) that can close connection when it stayed idle for too long. However, after all other tasks finish, Deno still wait for these timers.

Unfortunately, I haven't found a solution to this problem. Seems that setTimeout and setInterval are the only APIs in Deno for the timer and currently there is no way to have Deno not wait for some specific timer. 😢 (UPDATE: there will be a solution: https://github.com/denoland/deno/issues/6141)

Workaround if you are writing short-running applications:

  • Set idleTimeout to 0 in Client.connect() options to disable the idle timeout, or
  • Call Client.close() or Deno.exit() after queries

lideming avatar Oct 23 '20 19:10 lideming

Set idleTimeout to 0 in Client.connect() options to disable the idle timeout

Thanks. That seems to do the trick.

TradeIdeasPhilip avatar Oct 24 '20 04:10 TradeIdeasPhilip