Skip to content

Commit

Permalink
Don't crash on socket removal (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmcd authored Jun 10, 2024
1 parent af89474 commit 8b091ea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deno-http-worker",
"version": "0.0.13",
"version": "0.0.14",
"description": "",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
19 changes: 19 additions & 0 deletions src/DenoHTTPWorker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ describe("DenoHTTPWorker", { timeout: 1000 }, () => {
worker.terminate();
});

it("dont crash on socket removal", async () => {
let worker = await newDenoHTTPWorker(
`
export default { async fetch (req: Request): Promise<Response> {
await Deno.removeSync(Deno.args[0]);
return Response.json({ ok: req.url })
} }
`,
{ printOutput: true }
);
let json = await jsonRequest(worker, "https://localhost/hello?isee=you", {
headers: { accept: "application/json" },
});
expect(json).toEqual({
ok: "https://localhost/hello?isee=you",
});
worker.terminate();
});

it("json response multiple requests", async () => {
let worker = await newDenoHTTPWorker(
`
Expand Down
2 changes: 1 addition & 1 deletion src/DenoHTTPWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class denoHTTPWorker {
forceKill(this.#process.pid!);
}
this.#agent.destroy();
fs.rm(this.#socketFile);
fs.rm(this.#socketFile).catch(() => {});
for (let onexit of this.#onexitListeners) {
onexit(code ?? 1, signal ?? "");
}
Expand Down

0 comments on commit 8b091ea

Please sign in to comment.