Skip to content

Commit 09c58ea

Browse files
Sebastian McKenziebestander
authored andcommitted
probe queue for activity on network io to prevent stuck message - fixes #139 (#141)
1 parent 5bde489 commit 09c58ea

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

src/resolvers/exotics/_hosted-git.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ export default class HostedGitResolver extends ExoticResolver {
9090
let client = new Git(this.config, url, this.hash);
9191

9292
let out = await this.config.requestManager.request({
93-
url: `${url}/info/refs?service=git-upload-pack`
93+
url: `${url}/info/refs?service=git-upload-pack`,
94+
queue: this.resolver.fetchingQueue
9495
});
9596

9697
if (out) {
@@ -120,11 +121,12 @@ export default class HostedGitResolver extends ExoticResolver {
120121
let self = this; // TODO: babel bug...
121122
let commit = await this.getRefOverHTTP(url);
122123

123-
async function tryRegistry(registry) {
124+
let tryRegistry = async (registry) => {
124125
let filenames = registries[registry].filenames;
125126
for (let filename of filenames) {
126127
let file = await self.config.requestManager.request({
127-
url: self.constructor.getHTTPFileUrl(self.exploded, filename, commit)
128+
url: self.constructor.getHTTPFileUrl(self.exploded, filename, commit),
129+
queue: this.resolver.fetchingQueue
128130
});
129131
if (!file) continue;
130132

@@ -139,7 +141,7 @@ export default class HostedGitResolver extends ExoticResolver {
139141

140142
return json;
141143
}
142-
}
144+
};
143145

144146
let file = await tryRegistry(this.registry);
145147
if (file) return file;
@@ -155,7 +157,11 @@ export default class HostedGitResolver extends ExoticResolver {
155157
}
156158

157159
async hasHTTPCapability(url: string): Promise<boolean> {
158-
return (await this.config.requestManager.request({ url, method: "HEAD" })) !== false;
160+
return (await this.config.requestManager.request({
161+
url,
162+
method: "HEAD",
163+
queue: this.resolver.fetchingQueue
164+
})) !== false;
159165
}
160166

161167
async resolve(): Promise<Manifest> {

src/resolvers/registries/bower.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export default class BowerResolver extends RegistryResolver {
2222
}> {
2323
return this.config.requestManager.request({
2424
url: `${this.registryConfig.registry}/packages/${this.name}`,
25-
json: true
25+
json: true,
26+
queue: this.resolver.fetchingQueue
2627
});
2728
}
2829

src/util/blocking-queue.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export default class BlockingQueue {
2222

2323
this.running = map();
2424
this.queue = map();
25+
26+
// $FlowFixMe: for performance we refer to this in `stillActive`
27+
this.stuckTick = this.stuckTick.bind(this);
2528
}
2629

2730
concurrencyQueue: Array<Function>;
@@ -44,27 +47,29 @@ export default class BlockingQueue {
4447
[key: string]: boolean
4548
};
4649

47-
startStuckTimer() {
50+
stillActive() {
4851
if (this.stuckTimer) {
4952
clearTimeout(this.stuckTimer);
5053
}
5154

52-
this.stuckTimer = setTimeout(() => {
53-
if (this.runningCount === 1) {
54-
this.warnedStuck = true;
55-
console.warn(
56-
`[fbkpm] The ${JSON.stringify(this.alias)} blocking queue may be stuck. 5 seconds ` +
57-
`without any activity with 1 worker: ${Object.keys(this.running)[0]}`
58-
);
59-
}
60-
}, 5000);
55+
this.stuckTimer = setTimeout(this.stuckTick, 5000);
56+
}
57+
58+
stuckTick() {
59+
if (this.runningCount === 1) {
60+
this.warnedStuck = true;
61+
console.warn(
62+
`[fbkpm] The ${JSON.stringify(this.alias)} blocking queue may be stuck. 5 seconds ` +
63+
`without any activity with 1 worker: ${Object.keys(this.running)[0]}`
64+
);
65+
}
6166
}
6267

6368
push<T>(key: string, factory: () => Promise<T>): Promise<T> {
6469
if (this.first) {
6570
this.first = false;
6671
} else {
67-
this.startStuckTimer();
72+
this.stillActive();
6873
}
6974

7075
return new Promise((resolve, reject) => {

src/util/request-manager.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
import type { Reporter } from "../reporters/index.js";
13+
import BlockingQueue from "./blocking-queue.js";
1314
import * as constants from "../constants.js";
1415
import * as network from "./network.js";
1516
import map from "../util/map.js";
@@ -28,6 +29,7 @@ declare class RequestError extends Error {
2829
type RequestParams<T> = {
2930
url: string,
3031
method?: "GET" | "HEAD" | "POST" | "PUT",
32+
queue?: BlockingQueue,
3133
json?: boolean,
3234
forever?: boolean,
3335
headers?: {
@@ -218,6 +220,9 @@ export default class RequestManager {
218220
}
219221
});
220222

223+
let queue = params.queue;
224+
if (queue) req.on("data", queue.stillActive);
225+
221226
if (params.process) {
222227
params.process(req, resolve, reject);
223228
}

0 commit comments

Comments
 (0)