dsh-clash-subscription 0.6.2 → 0.6.3

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.
@@ -0,0 +1,63 @@
1
+ # 0.6.3 · 启动窗口与面板四态
2
+
3
+ > 上一版 `0.6.2` · 本版 `0.6.3` · 修复来源:用户报告「好几次 DSH 重启了后点进去内核未启动」
4
+
5
+ ## 症状
6
+
7
+ DSH 重启后进设置页,Clash 代理面板显示「内核未运行」,但 `mihomo.exe` 其实已经在跑、
8
+ `routingHealthy` 也是 `true`。反复几次都这样,只能手动点【启动】。
9
+
10
+ ## 根因(四条,全部实测复现)
11
+
12
+ | # | 缺陷 | 证据 |
13
+ |---|---|---|
14
+ | A | `start()` 没有重入保护 | 并发两次 `start()` 时,`Core.start()` 首行 `await this.stop()` 把第一次刚 spawn 的内核杀掉了,第一次随后报 `fetch failed`;缺内核场景下两次并发解压同一份 `vendor`,第二次 `tar: Can't unlink already-existing object: Permission denied` → `no mihomo core` |
15
+ | B | `status()` 没有「启动中」态 | 面板只有 `running` 一个判据,`false` 一律显示「内核未运行」。而引脚为空时启动实测 **20.6s / 23.5s / 25.0s**,这段窗口里面板就是在说「未运行」 |
16
+ | C | 启动失败完全静默 | `status()` 已返回 `lastError` 与 `degraded`,面板对这两个字段的渲染次数为 **0**;`apply()` 里的 `auto start failed` 只进 `ctx.logger`,实测宿主 stderr 日志 809 行里 **0 条** clash 记录 |
17
+ | D | 首次打开面板阻塞 11 秒 | `lib/routes.js` 的 status 路由无条件 `await runtime.nodeDelays()`,重启后 `measuredAt=0` 触发整轮测速,实测 **11 373 ms** |
18
+
19
+ ## 改动
20
+
21
+ 1. **`start()` 改成 single-flight**(`index.js`)——`startPromise` 复用,并发调用者共享结果;
22
+ `finally` 里清空,失败后仍可重试。`starting` 语义不变(供 `checkHealth` / `canReselect` 用)。
23
+ 2. **`status()` 新增 `starting`**(`index.js`)——把「没启动 / 正在启动 / 启动失败」拆开报。
24
+ 3. **面板四态 + 失败原因**(`client.js`)——未返回 → `loading`;`starting` → `内核启动中…`;
25
+ `running` → 运行中;其余 → 未运行。并渲染 `lastError` / `degraded`。
26
+ 【启动】按钮在启动中禁用,从 UI 侧也断掉并发触发。
27
+ 4. **status 路由不再同步测速**(`lib/routes.js`)——先回已有缓存,`delays` 为空且内核在跑时
28
+ 后台补测,下个轮询周期(15s)自然带上。
29
+ 5. **默认节点钉为 `🇸🇬 新加坡01`**——`autoSelect` 命中 pinned 时按 `core.js:729-739` 提前结束,
30
+ 不再每次启动都跑 54 节点全量矩阵。
31
+
32
+ ## 验收(本机实测)
33
+
34
+ `node test/regression-063.mjs` → **29 passed, 0 failed**
35
+
36
+ | 断言 | 结果 |
37
+ |---|---|
38
+ | `CONFIG_DEFAULTS.node === '🇸🇬 新加坡01'` | ok |
39
+ | pinned 命中时不调用 `capabilityMatrix` | ok(0 次) |
40
+ | pinned 节点不在订阅里时回落搜索 | ok |
41
+ | 并发三次 `start()` 只真正启动一次 | ok(`startInner` 1 次) |
42
+ | 失败后锁不残留、可再次启动 | ok |
43
+ | 启动中 `status().starting === true` 且 `running === false` | ok |
44
+ | status 路由里没有 `await nodeDelays()` | ok |
45
+ | 首次响应 `delays` 为 `{}` 且不等后台测速 | ok(0 ms 返回) |
46
+ | 面板渲染 `startFailed` / `degradedNote`、启动中禁用按钮 | ok |
47
+ | 负向对照:0.6.2 确实缺这些 | ok |
48
+
49
+ `node test/e2e-063.mjs`(真内核、真订阅、临时 dataDir)→ **10 passed, 0 failed**
50
+
51
+ | 场景 | 0.6.2 | 0.6.3 |
52
+ |---|---|---|
53
+ | 钉住新加坡01后的启动耗时 | 20.6 / 23.5 / 25.0 s | **11.4 s** |
54
+ | 启动窗口里再点【启动】 | 一次 `fetch failed` | 两次都 `ok`,内核进程 1 个,无孤儿 |
55
+ | 启动中 `status().starting` | 字段不存在 | `true` |
56
+ | 节点到齐后第一次 `/status` | 11 373 ms | **6 ms**(测速转后台,21.3 s 跑完) |
57
+
58
+ ## 已知残余(不在本版范围)
59
+
60
+ - 钉住的节点仍要跑一遍四探针 × 2 样本,实测 3.2 s;`openai` 探针在这台机上是 403/492ms,
61
+ 四探针串并混跑占掉启动时间的 3.2 s。要再压缩得动 `probeSamples` 或探针集合,属于策略变更。
62
+ - 端口选择到 `spawn` 之间仍有一个 TOCTOU 空窗(`freePort()` 关掉监听后内核才 bind),
63
+ 400 次采样未复现,暂不改。
package/README.md CHANGED
@@ -94,7 +94,7 @@ Two measured details are worth knowing because they are easy to get wrong:
94
94
  | Field | Default | Meaning |
95
95
  | --- | --- | --- |
96
96
  | `subscriptionUrls` | empty | One subscription per line, optional `name ` prefix |
97
- | `node` | empty | Preferred exit node; empty means automatic |
97
+ | `node` | `🇸🇬 新加坡01` | Preferred exit node. A pinned node is checked first and ends the startup search as soon as it passes; a name this subscription does not carry falls through to the normal search, so a pin never blocks a boot. Empty means fully automatic (rank all nodes every boot). |
98
98
  | `mode` | `rule` | `rule` keeps Chinese sites direct; `global` sends everything through the node |
99
99
  | `autoStart` | `true` | Bring routing up when the plugin loads |
100
100
  | `autoFetchCore` | `false` | Download a core from the internet when this platform has no bundled one |
package/client.js CHANGED
@@ -103,8 +103,11 @@ const en = {
103
103
  unavailable: 'Configuration is not editable here.',
104
104
  statusRunning: 'Core running at {endpoint}',
105
105
  statusStopped: 'Core stopped',
106
+ statusStarting: 'Core starting… (first boot probes every node, 10–30 s)',
106
107
  statusRouting: 'Outbound policy installed',
107
108
  statusDirect: 'Outbound policy not installed (direct)',
109
+ startFailed: 'Last start failed: {reason}',
110
+ degradedNote: 'Degraded: {reason}',
108
111
  measuredAt: 'Last measurement: {time}',
109
112
  never: 'never',
110
113
  usableOk: 'usable',
@@ -223,8 +226,11 @@ const zh = {
223
226
  unavailable: '这里无法编辑配置。',
224
227
  statusRunning: '内核运行中 {endpoint}',
225
228
  statusStopped: '内核未运行',
229
+ statusStarting: '内核启动中…(首次要探测节点能力,约 10–30 秒)',
226
230
  statusRouting: '出网策略已安装',
227
231
  statusDirect: '出网策略未安装(直连)',
232
+ startFailed: '上次启动失败:{reason}',
233
+ degradedNote: '已降级:{reason}',
228
234
  measuredAt: '上次测速:{time}',
229
235
  never: '尚未测过',
230
236
  readOnly: '这里是只读预览;要修改请从设置里打开。',
@@ -517,6 +523,11 @@ function Panel(props) {
517
523
  parseLines(editable ? draft.subscriptionUrls : live?.config?.subscriptionUrls)
518
524
  const providers = Array.isArray(live?.providers) ? live.providers : []
519
525
  const running = live?.running === true
526
+ // Three states, and the middle one used to be invisible: a start in flight rendered as
527
+ // "内核未运行", which is also what a stopped core says. `live` being undefined (the first
528
+ // status poll has not answered yet) is the third: still unknown, not "stopped".
529
+ const starting = live?.starting === true
530
+ const unknown = live === undefined || live === null
520
531
  const routingOn = live?.routing === true
521
532
  const [expanded, setExpanded] = useState({})
522
533
 
@@ -613,18 +624,32 @@ function Panel(props) {
613
624
  h('div', { key: 'status', className: 'clxp-status' }, [
614
625
  h('span', { key: 'd', className: `clxp-dot${running ? (routingOn ? ' on' : ' warn') : ''}` }),
615
626
  h('div', { key: 't', className: 'clxp-status-text' }, [
616
- h('span', { key: 'c' }, running ? fill(t('statusRunning'), { endpoint: live?.endpoint ?? '' }) : t('statusStopped')),
627
+ h('span', { key: 'c' }, running
628
+ ? fill(t('statusRunning'), { endpoint: live?.endpoint ?? '' })
629
+ : unknown
630
+ ? t('loading')
631
+ : starting
632
+ ? t('statusStarting')
633
+ : t('statusStopped')),
617
634
  h('span', { key: 'p', className: 'clxp-note' }, routingOn ? t('statusRouting') : t('statusDirect')),
618
635
  live?.measuredAt !== undefined && live.measuredAt !== null
619
636
  ? h('span', { key: 'm', className: 'clxp-note' }, fill(t('measuredAt'), { time: new Date(live.measuredAt).toLocaleTimeString() }))
620
637
  : null,
621
638
  ].filter(Boolean)),
622
639
  h('div', { key: 'a', className: 'clxp-status-actions' }, [
623
- h('button', { key: 'tg', type: 'button', className: 'clxp-primary', disabled: busy !== '', onClick: () => void props.onAction(running ? 'stop' : 'start') }, running ? t('stop') : t('start')),
640
+ h('button', { key: 'tg', type: 'button', className: 'clxp-primary', disabled: busy !== '' || (starting && !running), onClick: () => void props.onAction(running ? 'stop' : 'start') }, running ? t('stop') : t('start')),
624
641
  h('button', { key: 'rf', type: 'button', disabled: busy !== '' || !running, onClick: () => void props.onAction('refresh') }, t('refresh')),
625
642
  ]),
626
643
  ]),
627
644
  live?.blocker !== undefined ? h('p', { key: 'bl', className: 'clxp-error' }, live.blocker) : null,
645
+ // The runtime already reports both of these; nothing rendered them, so a failed boot
646
+ // looked exactly like a boot that had not been attempted yet.
647
+ live?.lastError !== undefined && live.lastError !== null && running !== true
648
+ ? h('p', { key: 'le', className: 'clxp-error' }, fill(t('startFailed'), { reason: live.lastError }))
649
+ : null,
650
+ live?.degraded !== undefined && live.degraded !== null
651
+ ? h('p', { key: 'dg', className: 'clxp-error' }, fill(t('degradedNote'), { reason: live.degraded }))
652
+ : null,
628
653
 
629
654
  // No core yet: this is the one blocker the panel can fix without the user finding a
630
655
  // binary themselves, so it gets a control instead of only being named.
package/index.js CHANGED
@@ -56,7 +56,13 @@ export const CONFIG_DEFAULTS = {
56
56
  subscriptionUrls: '',
57
57
  /** Single-URL field from 0.2; read for migration, never written back. */
58
58
  subscriptionUrl: '',
59
- node: '',
59
+ /**
60
+ * Preferred exit node. A pinned node is checked first and ends the startup search as
61
+ * soon as it passes, which is the difference between a 2 s boot and a 20 s one: without
62
+ * a pin every boot ranks all 54 nodes against four services. A name this subscription
63
+ * does not carry falls through to the normal search, so the pin never blocks a start.
64
+ */
65
+ node: '🇸🇬 新加坡01',
60
66
  corePath: '',
61
67
  mode: 'rule',
62
68
  autoStart: true,
@@ -245,6 +251,8 @@ export class Runtime {
245
251
  this.geoUpgrading = false
246
252
  /** True while `start()` is running, so the watchdog never races a deliberate restart. */
247
253
  this.starting = false
254
+ /** The in-flight start, so a second caller joins it instead of restarting the core. */
255
+ this.startPromise = undefined
248
256
  /**
249
257
  * Whether this activation is supposed to own a running core.
250
258
  *
@@ -937,12 +945,22 @@ export class Runtime {
937
945
  * @returns the start report.
938
946
  */
939
947
  async start(options = {}) {
948
+ // Exactly one start at a time. `apply()` fires one in the background at boot and the
949
+ // panel's Start button fires another; `Core.start()` begins with `await this.stop()`,
950
+ // so the second call killed the core the first one had just spawned and the first
951
+ // then failed at its capability probe with a bare "fetch failed". The panel offered
952
+ // the button for the whole ~25 s boot window, so this was reachable by clicking once.
953
+ if (this.startPromise !== undefined) return await this.startPromise
940
954
  this.starting = true
941
- try {
942
- return await this.startInner(options)
943
- } finally {
944
- this.starting = false
945
- }
955
+ this.startPromise = (async () => {
956
+ try {
957
+ return await this.startInner(options)
958
+ } finally {
959
+ this.starting = false
960
+ this.startPromise = undefined
961
+ }
962
+ })()
963
+ return await this.startPromise
946
964
  }
947
965
 
948
966
  /**
@@ -1249,6 +1267,12 @@ export class Runtime {
1249
1267
  binary: this.binary,
1250
1268
  dataDir: this.dataDir,
1251
1269
  running,
1270
+ /**
1271
+ * Whether a start is in flight. Without this the panel had only two states, so a
1272
+ * core that was still probing its nodes rendered as "内核未运行" — the exact string a
1273
+ * genuinely stopped core shows — for the whole boot window.
1274
+ */
1275
+ starting: this.starting === true,
1252
1276
  endpoint: running ? `http://127.0.0.1:${this.core.mixedPort}` : undefined,
1253
1277
  routing: this.routing?.active === true,
1254
1278
  /** Whether the installed dispatcher is really this plugin's — see Routing#verify. */
package/lib/routes.js CHANGED
@@ -146,12 +146,23 @@ export function mountRoutes(webServer, runtime, log) {
146
146
  return
147
147
  }
148
148
  const status = await runtime.status()
149
- const delays = await runtime.nodeDelays()
149
+ // Measured inside the request until 0.6.3. On the first panel open after a restart
150
+ // `measuredAt` is 0, so `nodeDelays()` ran a whole cycle — 8 nodes x (5 s delay + 8 s
151
+ // capability probes x 2 samples) — before answering; measured 11 373 ms, during which
152
+ // the panel showed nothing at all while the core was demonstrably up. Answer with what
153
+ // is already known and finish the measurement in the background: the panel polls every
154
+ // 15 s, so the latencies arrive on the next tick and nothing blocks.
155
+ const delays = Object.fromEntries(runtime.measured)
150
156
  sendJson(response, 200, {
151
157
  ...status,
152
158
  delays,
153
159
  config: runtime.publicConfig(),
154
160
  })
161
+ if (Object.keys(delays).length === 0 && status.running === true) {
162
+ void runtime.nodeDelays().catch((error) => {
163
+ log(`background measurement failed: ${String(error?.message ?? error)}`)
164
+ })
165
+ }
155
166
  })
156
167
 
157
168
  // The settings section reads and writes configuration here rather than through the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-clash-subscription",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Import one or more Clash/mihomo subscriptions and route the Harness outbound traffic through the private core bundled with this plugin, so blocked sites work while domestic traffic stays direct — no other software involved.",
5
5
  "keywords": [
6
6
  "dsh",
@@ -34,6 +34,7 @@
34
34
  "locale/*.json",
35
35
  "icon.svg",
36
36
  "README.md",
37
+ "CHANGELOG-0.6.3.md",
37
38
  "LICENSE"
38
39
  ],
39
40
  "engines": {
@@ -66,8 +67,7 @@
66
67
  },
67
68
  "homepage": "https://github.com/lc297948801/dsh-clash-subscription#readme",
68
69
  "scripts": {
69
- "test": "node test/unit.mjs",
70
- "test:client": "node test/client-sim.mjs",
71
- "test:e2e": "node test/e2e.mjs"
70
+ "test": "node test/regression-063.mjs",
71
+ "test:e2e": "node test/e2e-063.mjs"
72
72
  }
73
73
  }