Skip to content

Commit fc042d0

Browse files
jacdebugfacebook-github-bot
authored andcommittedJun 23, 2022
End watchman client on calling MetroFileMap end method.
Summary: End watchman client on `MetroFileMap` end method. This will kill any stale child watchman process that is talking long time to execute. Reviewed By: arushikesarwani94 Differential Revision: D37229202 fbshipit-source-id: ad4481f087309e42f286e48da280c58765f18b34
1 parent c093875 commit fc042d0

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed
 

‎packages/metro-file-map/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"license": "MIT",
1515
"dependencies": {
16+
"abort-controller": "^3.0.0",
1617
"anymatch": "^3.0.3",
1718
"debug": "^2.2.0",
1819
"fb-watchman": "^2.0.0",

‎packages/metro-file-map/src/crawlers/watchman.js

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ module.exports = async function watchmanCrawl(
114114

115115
perfLogger?.point('watchmanCrawl_start');
116116
const client = new watchman.Client();
117+
options.abortSignal?.addEventListener('abort', () => client.end());
117118

118119
perfLogger?.point('watchmanCrawl/negotiateCapabilities_start');
119120
// https://facebook.github.io/watchman/docs/capabilities.html

‎packages/metro-file-map/src/flow-types.js

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export type ChangeEvent = {
6161
export type Console = typeof global.console;
6262

6363
export type CrawlerOptions = {
64+
abortSignal: ?AbortSignal,
6465
computeSha1: boolean,
6566
enableSymlinks: boolean,
6667
data: InternalData,

‎packages/metro-file-map/src/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ import {escapePathForRegex} from 'jest-regex-util';
5656
// $FlowFixMe[untyped-import] - jest-worker
5757
import {Worker} from 'jest-worker';
5858
import * as path from 'path';
59+
// $FlowFixMe[untyped-import] - this is a polyfill
60+
import AbortController from 'abort-controller';
5961

6062
const nodeCrawl = require('./crawlers/node');
6163
const watchmanCrawl = require('./crawlers/watchman');
@@ -237,6 +239,7 @@ export default class HasteMap extends EventEmitter {
237239
_watchers: Array<Watcher>;
238240
_worker: ?WorkerInterface;
239241
_cacheManager: CacheManager;
242+
_crawlerAbortController: typeof AbortController;
240243

241244
static create(options: InputOptions): HasteMap {
242245
return new HasteMap(options);
@@ -320,6 +323,7 @@ export default class HasteMap extends EventEmitter {
320323
this._watchers = [];
321324
this._worker = null;
322325
this._options.perfLogger?.point('constructor_end');
326+
this._crawlerAbortController = new AbortController();
323327
}
324328

325329
static getCacheFilePath(
@@ -781,6 +785,7 @@ export default class HasteMap extends EventEmitter {
781785
const crawl =
782786
canUseWatchman && this._options.useWatchman ? watchmanCrawl : nodeCrawl;
783787
const crawlerOptions: CrawlerOptions = {
788+
abortSignal: this._crawlerAbortController.signal,
784789
computeSha1: options.computeSha1,
785790
data: hasteMap,
786791
enableSymlinks: options.enableSymlinks,
@@ -1118,6 +1123,7 @@ export default class HasteMap extends EventEmitter {
11181123
await Promise.all(this._watchers.map(watcher => watcher.close()));
11191124

11201125
this._watchers = [];
1126+
this._crawlerAbortController.abort();
11211127
}
11221128

11231129
/**

‎yarn.lock

+12
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,13 @@ abab@^2.0.3:
14491449
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.3.tgz#623e2075e02eb2d3f2475e49f99c91846467907a"
14501450
integrity sha512-tsFzPpcttalNjFBCFMqsKYQcWxxen1pgJR56by//QwvJc4/OUS3kPOOttx2tSIfjsylB0pYu7f5D3K1RCxUnUg==
14511451

1452+
abort-controller@^3.0.0:
1453+
version "3.0.0"
1454+
resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392"
1455+
integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==
1456+
dependencies:
1457+
event-target-shim "^5.0.0"
1458+
14521459
absolute-path@^0.0.0:
14531460
version "0.0.0"
14541461
resolved "https://registry.yarnpkg.com/absolute-path/-/absolute-path-0.0.0.tgz#a78762fbdadfb5297be99b15d35a785b2f095bf7"
@@ -3312,6 +3319,11 @@ esutils@^2.0.2:
33123319
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
33133320
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==
33143321

3322+
event-target-shim@^5.0.0:
3323+
version "5.0.1"
3324+
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789"
3325+
integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==
3326+
33153327
exec-sh@^0.3.2:
33163328
version "0.3.4"
33173329
resolved "https://registry.yarnpkg.com/exec-sh/-/exec-sh-0.3.4.tgz#3a018ceb526cc6f6df2bb504b2bfe8e3a4934ec5"

0 commit comments

Comments
 (0)
Please sign in to comment.