com.jimuwd.xian.registry-proxy 1.1.13 → 1.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server/index.js
CHANGED
|
@@ -152,7 +152,7 @@ async function fetchFromRegistry(registry, targetUrl, reqFromDownstreamClient, l
|
|
|
152
152
|
logger.debug(() => `Replace 'Host=${mergedHeaders.host}' header in downstream request to upstream 'Host=${upstreamHost}' header when proxying to upstream ${targetUrl}.`);
|
|
153
153
|
mergedHeaders.host = upstreamHost;
|
|
154
154
|
}
|
|
155
|
-
const response = await fetch(targetUrl, { headers: mergedHeaders });
|
|
155
|
+
const response = await fetch(targetUrl, { headers: mergedHeaders, redirect: 'manual' });
|
|
156
156
|
if (response.ok) {
|
|
157
157
|
logger.debug(() => `Success response from upstream ${targetUrl}: ${response.status} ${response.statusText}
|
|
158
158
|
content-type=${response.headers.get('content-type')} content-encoding=${response.headers.get('content-encoding')} content-length=${response.headers.get('content-length')} transfer-encoding=${response.headers.get('transfer-encoding')}`);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
export default class
|
|
1
|
+
export default class ReentrantConcurrencyLimiter {
|
|
2
2
|
readonly maxConcurrency: number;
|
|
3
3
|
private current;
|
|
4
4
|
private queue;
|
|
5
|
+
private executionContexts;
|
|
5
6
|
constructor(maxConcurrency: number);
|
|
7
|
+
private getContextId;
|
|
6
8
|
acquire(): Promise<void>;
|
|
7
9
|
release(): void;
|
|
8
10
|
run<T>(task: () => Promise<T>): Promise<T>;
|
|
@@ -1,34 +1,61 @@
|
|
|
1
|
-
export default class
|
|
1
|
+
export default class ReentrantConcurrencyLimiter {
|
|
2
2
|
maxConcurrency;
|
|
3
3
|
current = 0;
|
|
4
4
|
queue = [];
|
|
5
|
+
executionContexts = new Map(); // 跟踪执行上下文及其嵌套深度
|
|
5
6
|
constructor(maxConcurrency) {
|
|
6
7
|
if (maxConcurrency <= 0) {
|
|
7
8
|
throw new Error("maxConcurrency must be positive");
|
|
8
9
|
}
|
|
9
10
|
this.maxConcurrency = maxConcurrency;
|
|
10
11
|
}
|
|
12
|
+
getContextId() {
|
|
13
|
+
// 使用Error堆栈生成唯一上下文ID(适用于同步/异步嵌套)
|
|
14
|
+
try {
|
|
15
|
+
throw new Error();
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
return e.stack;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
11
21
|
async acquire() {
|
|
22
|
+
const contextId = this.getContextId();
|
|
23
|
+
const depth = this.executionContexts.get(contextId) || 0;
|
|
24
|
+
if (depth > 0) {
|
|
25
|
+
// 嵌套调用,不占用新槽位
|
|
26
|
+
this.executionContexts.set(contextId, depth + 1);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
12
29
|
if (this.current < this.maxConcurrency) {
|
|
13
30
|
this.current++;
|
|
31
|
+
this.executionContexts.set(contextId, 1);
|
|
14
32
|
return;
|
|
15
33
|
}
|
|
16
34
|
return new Promise((resolve) => {
|
|
17
|
-
this.queue.push(
|
|
35
|
+
this.queue.push(() => {
|
|
36
|
+
this.current++;
|
|
37
|
+
this.executionContexts.set(contextId, 1);
|
|
38
|
+
resolve();
|
|
39
|
+
});
|
|
18
40
|
});
|
|
19
41
|
}
|
|
20
42
|
release() {
|
|
21
|
-
|
|
43
|
+
const contextId = this.getContextId();
|
|
44
|
+
const depth = this.executionContexts.get(contextId);
|
|
45
|
+
if (!depth) {
|
|
22
46
|
throw new Error("release() called without acquire()");
|
|
23
47
|
}
|
|
48
|
+
if (depth > 1) {
|
|
49
|
+
// 嵌套调用退出,减少深度
|
|
50
|
+
this.executionContexts.set(contextId, depth - 1);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
// 最外层调用结束
|
|
54
|
+
this.executionContexts.delete(contextId);
|
|
24
55
|
this.current--;
|
|
25
56
|
const next = this.queue.shift();
|
|
26
57
|
if (next) {
|
|
27
|
-
//
|
|
28
|
-
Promise.resolve().then(() => {
|
|
29
|
-
this.current++;
|
|
30
|
-
next();
|
|
31
|
-
});
|
|
58
|
+
Promise.resolve().then(next); // 异步触发下一个任务
|
|
32
59
|
}
|
|
33
60
|
}
|
|
34
61
|
async run(task) {
|