From 6001f86f0a14a85e94522b01f38aff27714ee3c8 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Fri, 8 Dec 2023 04:51:01 -0800 Subject: [PATCH] Destroy HTTP cache connections on timeout Summary: Changelog: **[Fix]**: Destroy HTTP cache connections on timeout instead of hanging. From Node's [docs](https://nodejs.org/api/http.html#event-timeout): > [The `'timeout'` event is emitted] when the underlying socket times out from inactivity. This only notifies that the socket has been idle. The request must be destroyed manually. Reviewed By: robhogan Differential Revision: D51978782 fbshipit-source-id: 60bba1d35283853c9d3e27133c77045562f7148d --- packages/metro-cache/src/stores/HttpStore.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/metro-cache/src/stores/HttpStore.js b/packages/metro-cache/src/stores/HttpStore.js index fcefa64af0..8acfe4f63e 100644 --- a/packages/metro-cache/src/stores/HttpStore.js +++ b/packages/metro-cache/src/stores/HttpStore.js @@ -153,6 +153,10 @@ class HttpStore { reject(new NetworkError(err.message, err.code)); }); + req.on('timeout', () => { + req.destroy(new Error('Request timed out')); + }); + req.end(); }); } @@ -195,6 +199,10 @@ class HttpStore { res.resume(); }); + req.on('timeout', () => { + req.destroy(new Error('Request timed out')); + }); + gzip.pipe(req); if (value instanceof Buffer) {