From 6f4dc16c598cd98d4afc97e1efcfc878250592ec Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Thu, 11 May 2023 02:16:52 +0300 Subject: [PATCH] Handle etcd connection errors correctly in mon (unhandled error events) --- mon/mon.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mon/mon.js b/mon/mon.js index d58cc31e..93eed7db 100644 --- a/mon/mon.js +++ b/mon/mon.js @@ -1823,6 +1823,7 @@ function POST(url, body, timeout) clearTimeout(timer_id); let res_body = ''; res.setEncoding('utf8'); + res.on('error', (error) => ok({ error })); res.on('data', chunk => { res_body += chunk; }); res.on('end', () => { @@ -1842,6 +1843,8 @@ function POST(url, body, timeout) } }); }); + req.on('error', (error) => ok({ error })); + req.on('close', () => ok({ error: new Error('Connection closed prematurely') })); req.write(body_text); req.end(); });