Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't block with readFileSync in remote recording finish #145

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/hooks/http.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;

Expand Down Expand Up @@ -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:
Expand Down