postgres icon indicating copy to clipboard operation
postgres copied to clipboard

`ConnectionError` - Session terminated by database without notifying the library

Open linhub15 opened this issue 3 years ago • 1 comments

Using a cloud managed DB often terminates sessions without notifying the library. This causes ConnectionError because the library was not notified of the cancelled connection.

There is a TODO comment mentioned that this will be fixed.

... will be removed once we move to async handling of messages by the frontend ... https://github.com/denodrivers/postgres/blob/main/connection/connection.ts#L167-L171

Is there a workaround in the meantime?

linhub15 avatar Sep 19 '22 04:09 linhub15

Would it be wrong to recursively call Connection.query(...)?

https://github.com/denodrivers/postgres/blob/8a07131efa17f4a6bcab86fd81407f149de93449/connection/connection.ts#L953-L959

} catch (e) { 
   if (e instanceof ConnectionError) { 
     await this.end();
+    return await this.query(query);
   } 
   throw e;
 } finally {
   this.#queryLock.push(undefined);

linhub15 avatar Sep 20 '22 07:09 linhub15