Skip to content

Commit

Permalink
Destroy HTTP cache connections on timeout
Browse files Browse the repository at this point in the history
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
  • Loading branch information
motiz88 authored and facebook-github-bot committed Dec 8, 2023
1 parent e223a2e commit 6001f86
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/metro-cache/src/stores/HttpStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ class HttpStore<T> {
reject(new NetworkError(err.message, err.code));
});

req.on('timeout', () => {
req.destroy(new Error('Request timed out'));
});

req.end();
});
}
Expand Down Expand Up @@ -195,6 +199,10 @@ class HttpStore<T> {
res.resume();
});

req.on('timeout', () => {
req.destroy(new Error('Request timed out'));
});

gzip.pipe(req);

if (value instanceof Buffer) {
Expand Down

0 comments on commit 6001f86

Please sign in to comment.