From a6a58378fb3b3f1a611ff45025c9746086ff5ff9 Mon Sep 17 00:00:00 2001 From: zermelo-wisen Date: Wed, 24 Apr 2024 17:23:58 +0300 Subject: [PATCH] fix: Don't use blocking fs function in remote recording finish --- src/hooks/http.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/hooks/http.ts b/src/hooks/http.ts index bbbb6e1e..5f01c13e 100644 --- a/src/hooks/http.ts +++ b/src/hooks/http.ts @@ -1,5 +1,4 @@ import assert from "node:assert"; -import { readFileSync, rmSync } from "node:fs"; import type http from "node:http"; import type { ClientRequest, IncomingMessage, ServerResponse } from "node:http"; import type https from "node:https"; @@ -18,6 +17,7 @@ import { startRequestRecording, } from "../recorder"; import { getTime } from "../util/getTime"; +import { readFile, rm } from "node:fs/promises"; type HTTP = typeof http | typeof https; @@ -394,14 +394,22 @@ function handleRemoteRecording( if (remoteRunning) { remoteRunning = false; const recording = getRemoteRecording(); + const reset = () => { + info("Remote recording finished"); + startProcessRecording(); // just so there's always a recording running + }; if (recording.finish()) { res.writeHead(200); const { path } = recording; - res.end(readFileSync(path)); - rmSync(path); - } else res.writeHead(200).end("{}"); - info("Remote recording finished"); - startProcessRecording(); // just so there's always a recording running + void (async () => { + res.end(await readFile(path)); + await rm(path); + reset(); + })(); + } else { + res.writeHead(200).end("{}"); + reset(); + } } else res.writeHead(404).end("No recording is in progress"); break; default: