From 3428d53afe367cb0376b843e368ced9ee213c3a6 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 8 May 2023 12:03:50 +0100 Subject: [PATCH] Merge pull request #12938 from overleaf/jpa-leaks-filestore [filestore] cacheWarm: destroy file stream when not piping into response GitOrigin-RevId: a0fb14e5ececd28d8d9dbed8cd3a5622c81b8230 --- services/filestore/app/js/FileController.js | 1 + services/filestore/test/acceptance/js/FilestoreTests.js | 8 ++++++++ services/filestore/test/unit/js/FileControllerTests.js | 4 +++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/services/filestore/app/js/FileController.js b/services/filestore/app/js/FileController.js index 7304e4d6ba..a97869258a 100644 --- a/services/filestore/app/js/FileController.js +++ b/services/filestore/app/js/FileController.js @@ -67,6 +67,7 @@ function getFile(req, res, next) { } if (req.query.cacheWarm) { + fileStream.destroy() return res.sendStatus(200).end() } diff --git a/services/filestore/test/acceptance/js/FilestoreTests.js b/services/filestore/test/acceptance/js/FilestoreTests.js index 2d09e81253..4d3d8e6a00 100644 --- a/services/filestore/test/acceptance/js/FilestoreTests.js +++ b/services/filestore/test/acceptance/js/FilestoreTests.js @@ -901,6 +901,14 @@ describe('Filestore', function () { expect(response.status).to.equal(200) }) + it('should not leak sockets', async function () { + const response1 = await fetch(previewFileUrl) + expect(response1.status).to.equal(200) + const response2 = await fetch(previewFileUrl) + expect(response2.status).to.equal(200) + await expectNoSockets() + }) + it("should respond with only an 'OK'", async function () { // note: this test relies of the imagemagick conversion working const response = await fetch(previewFileUrl) diff --git a/services/filestore/test/unit/js/FileControllerTests.js b/services/filestore/test/unit/js/FileControllerTests.js index 11b80a7d09..508db8b153 100644 --- a/services/filestore/test/unit/js/FileControllerTests.js +++ b/services/filestore/test/unit/js/FileControllerTests.js @@ -22,7 +22,9 @@ describe('FileController', function () { }, } const fileSize = 1234 - const fileStream = 'fileStream' + const fileStream = { + destroy() {}, + } const projectId = 'projectId' const fileId = 'file_id' const bucket = 'user_files'