diff --git a/__tests__/misc.ts b/__tests__/misc.ts index 33f001a..b8ba23e 100644 --- a/__tests__/misc.ts +++ b/__tests__/misc.ts @@ -76,3 +76,17 @@ describe("Serialize reqeust serializes an incoming request", () => { expect(ser.parameters.petId).toBe("69"); }); }); + +describe("Mitm internal keepAlive", () => { + it("Properly destroys connection with keep alive", async () => { + const agent = new https.Agent({ keepAlive: true }); + for (let i = 1; i < 10000; i++) { + await new Promise((resolve, reject) => { + https.get("https://example.com", { agent }, res => { + res.on("data", d => {}); + res.on("end", resolve); + }); + }); + } + }); +}); diff --git a/src/index.ts b/src/index.ts index d42704c..49a4a7b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -106,6 +106,8 @@ class MockAPI { } catch (err) { res.statusCode = 500; res.end(err.message); + } finally { + req.destroy(); } }); }