From e6a331433af68716c10ed9813f83aaeba2053462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 13 Jun 2018 19:54:34 +0200 Subject: [PATCH] Handle error when client disconnects in copyto requests --- app/controllers/copy_controller.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/controllers/copy_controller.js b/app/controllers/copy_controller.js index 6509c1ef..f4cd4216 100644 --- a/app/controllers/copy_controller.js +++ b/app/controllers/copy_controller.js @@ -113,6 +113,13 @@ function handleCopyTo (logger) { }) .on('end', () => responseEnded = true); + pgstream.on('error', (err) => { + metrics.end(null, err); + pgstream.unpipe(res); + + return next(err); + }); + pgstream .on('data', data => metrics.addSize(data.length)) .pipe(res);