From a4bf5fa99531d11bd3db108e5144e4b5474c6880 Mon Sep 17 00:00:00 2001 From: Rasmus Porsager Date: Fri, 2 Jun 2023 12:01:39 +0200 Subject: [PATCH] Don't crash on errors in logical streaming, but log and reconnect --- src/subscribe.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/subscribe.js b/src/subscribe.js index 95a92ad7..7a70842e 100644 --- a/src/subscribe.js +++ b/src/subscribe.js @@ -97,11 +97,15 @@ export default function Subscribe(postgres, options) { } stream.on('data', data) - stream.on('error', sql.close) + stream.on('error', error) stream.on('close', sql.close) return { stream, state: xs.state } + function error(e) { + console.error('Unexpected error during logical streaming - reconnecting', e) + } + function data(x) { if (x[0] === 0x77) parse(x.subarray(25), state, sql.options.parsers, handle, options.transform)