An unclosed client may cause Deno from exiting automatically
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
idleTimeoutto0inClient.connect()options to disable the idle timeout, or - Call
Client.close()orDeno.exit()after queries
Set idleTimeout to 0 in Client.connect() options to disable the idle timeout
Thanks. That seems to do the trick.