From 11da21cac23ff3101b4c8a10f1166d2762ba482c Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Thu, 19 Oct 2023 11:04:29 +0200 Subject: [PATCH] ci: try to fix request timeouts (#11190) --- .github/workflows/changed-packages.yml | 1 + packages/testserver/src/index.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/.github/workflows/changed-packages.yml b/.github/workflows/changed-packages.yml index 77ea1bbf..bcf53f32 100644 --- a/.github/workflows/changed-packages.yml +++ b/.github/workflows/changed-packages.yml @@ -38,6 +38,7 @@ jobs: - 'packages/browsers/src/browser-data/firefox.ts' - 'packages/puppeteer/**' - 'packages/puppeteer-core/**' + - 'packages/testserver/**' - 'docker/**' - 'test/**' - 'test-d/**' diff --git a/packages/testserver/src/index.ts b/packages/testserver/src/index.ts index 153e4d19..1e3b40e9 100644 --- a/packages/testserver/src/index.ts +++ b/packages/testserver/src/index.ts @@ -66,6 +66,7 @@ export class TestServer { #csp = new Map(); #gzipRoutes = new Set(); #requestSubscribers = new Map(); + #requests = new Set(); static async create(dirPath: string): Promise { let res!: (value: unknown) => void; @@ -192,12 +193,20 @@ export class TestServer { subscriber.reject.call(undefined, error); } this.#requestSubscribers.clear(); + for (const request of this.#requests.values()) { + if (!request.writableEnded) { + request.end(); + } + } + this.#requests.clear(); } #onRequest: RequestListener = ( request: TestIncomingMessage, response ): void => { + this.#requests.add(response); + request.on('error', (error: {code: string}) => { if (error.code === 'ECONNRESET') { response.end(); @@ -271,6 +280,12 @@ export class TestServer { } readFile(filePath, (err, data) => { + // This can happen if the request is not awaited but started + // in the test and get clean via `reset()` + if (response.writableEnded) { + return; + } + if (err) { response.statusCode = 404; response.end(`File not found: ${filePath}`);