mihomo-cli 4.7.5 → 4.7.6
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/CHANGELOG.md +21 -0
- package/dist/index.js +17 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.7.6] - 2026-09-07
|
|
4
|
+
|
|
5
|
+
用户实测报告的单点修复:`mihomo stop` 或 `mihomo tun` 之后,`mihomo start` **再也起不来**。单测 314(+4)。
|
|
6
|
+
|
|
7
|
+
### 修复
|
|
8
|
+
|
|
9
|
+
- **`start` 被 `stop`/`tun` 留下的持久 disable 位永久卡死**:v4.7.5 给 `startService` 加的并发防线判据用错了——锁内查到 disabled 就直接 return,既不 `enable` 也不 `bootstrap`。但 disable 位有**两种来源,语义完全相反**:一种是上次 `stop`/`tun` 留下的**持久**状态(该位存在 plist 之外,launchctl 没有清除动词,会一直躺着直到被 `enable`),另一种才是「本次执行**期间**另一终端跑了 `stop`」这个真正要防的并发。单次采样把两者抹平,于是前者被当成后者:`stop`/`tun` 之后的**每一次** `start` 都静默什么都不做,内核永不被 launchd 拉起,唯一出路是用户手动 `launchctl enable`。
|
|
10
|
+
|
|
11
|
+
失效面全是误导:报错是「启动失败: 内核未能进入运行状态」(走的是非 crashed 分支),附的日志路径**从未被创建过**——用户据此以为是配置或内核的问题,手动直跑同参数的内核却一切正常;而 CLI 自己的文案还在承诺「TUN 用完后 `mihomo start` 可恢复」「`stop` 后 `mihomo start` 可恢复服务」。
|
|
12
|
+
|
|
13
|
+
修法是**收窄判据而非删掉防线**(直接删能修好现象,但会把并发保护一起删了):判据收口为纯函数 `shouldAbortStartOnDisable(disabledBefore, disabledNow)`,只有「期间新出现」才算并发 stop。快照取自 `cmdStart` 开头(订阅自动更新等慢速阶段**之前**)已有的 `getServiceStatus()`,经 `launchOrRestart` 透传——在 `startService` 内部现取会退化回原缺陷。另把并发取消单独成一条错误(「启动已取消:期间检测到 stop」),此前它也落进 `assertServiceHealthy`,意味着真并发场景同样会看到那句指错方向的「内核未能进入运行状态」。
|
|
14
|
+
|
|
15
|
+
顺带修掉 `uninstallService` 头注释里已失效的一句(「`startService` 恒无条件 `enable`」——v4.7.5 起就不成立,这处自相矛盾正好佐证了防线与原设计意图冲突)。
|
|
16
|
+
|
|
17
|
+
**教训**:给并发场景加防线时要问一句「这个信号除了并发,还有没有别的来源」。disable 位的两种来源语义相反,而「查一下当前是否 disabled」这个看似自然的判据把它们抹平了。
|
|
18
|
+
|
|
19
|
+
### 测试
|
|
20
|
+
|
|
21
|
+
- `shouldAbortStartOnDisable` 四条组合全锁(`service.spec.ts`)。**反向验证过**:把判据改回旧实现后,精确只有「开始前就存在 → 必须照常启动」这条失败,其余三条仍过——说明测试锁的是缺陷本身,不是顺带的行为
|
|
22
|
+
- launchd 语义用一次性 label + 桩内核真机实测(验完即 `bootout`,无残留):确认 disabled 下 `bootstrap` 是**硬失败** `Bootstrap failed: 5: Input/output error`(故只删 early-return 而不 `enable` 会换一种方式失败),`enable` → `bootstrap` 后 `state = running` 并拿到真实 pid
|
|
23
|
+
|
|
3
24
|
## [4.7.5] - 2026-09-06
|
|
4
25
|
|
|
5
26
|
第二轮独立复审,聚焦**同族缺口**:三处缺陷有共同模式——防线或测试断言只铺了一条路径,同族的另一条躺在盲区里。另清理三处过度设计。单测 310(+20)。
|
package/dist/index.js
CHANGED
|
@@ -5063,7 +5063,10 @@ async function installService(wasRunning) {
|
|
|
5063
5063
|
disableServiceAutoStart();
|
|
5064
5064
|
}
|
|
5065
5065
|
}
|
|
5066
|
-
|
|
5066
|
+
function shouldAbortStartOnDisable(disabledBefore, disabledNow) {
|
|
5067
|
+
return !disabledBefore && disabledNow;
|
|
5068
|
+
}
|
|
5069
|
+
async function startService(disabledBefore) {
|
|
5067
5070
|
assertServiceLabelSafe();
|
|
5068
5071
|
ensureServiceSymlink();
|
|
5069
5072
|
if (!isServiceInstalled()) {
|
|
@@ -5087,13 +5090,16 @@ async function startService() {
|
|
|
5087
5090
|
bootoutService();
|
|
5088
5091
|
await waitUntilUnloaded();
|
|
5089
5092
|
rotateAndCleanupLogs();
|
|
5093
|
+
let started = true;
|
|
5090
5094
|
withFileLock(PATHS.serviceLock, () => {
|
|
5091
|
-
if (isServiceDisabledInLaunchd()) {
|
|
5095
|
+
if (shouldAbortStartOnDisable(disabledBefore, isServiceDisabledInLaunchd())) {
|
|
5096
|
+
started = false;
|
|
5092
5097
|
return;
|
|
5093
5098
|
}
|
|
5094
5099
|
runLaunchctlOrThrow(["enable", serviceTarget()], "\u542F\u7528\u670D\u52A1");
|
|
5095
5100
|
runLaunchctlOrThrow(["bootstrap", bootstrapDomain(), PATHS.userAgentPlist], "\u542F\u52A8\u670D\u52A1");
|
|
5096
5101
|
});
|
|
5102
|
+
return { started };
|
|
5097
5103
|
}
|
|
5098
5104
|
function disableServiceAutoStart() {
|
|
5099
5105
|
assertServiceLabelSafe();
|
|
@@ -5496,7 +5502,7 @@ function getRunningState(serviceStatus) {
|
|
|
5496
5502
|
function isRestartNeededOnChange() {
|
|
5497
5503
|
return getRunningState().running;
|
|
5498
5504
|
}
|
|
5499
|
-
async function launchOrRestart(mode) {
|
|
5505
|
+
async function launchOrRestart(mode, disabledBefore = false) {
|
|
5500
5506
|
if (mode === "tun") {
|
|
5501
5507
|
const result = await startTun();
|
|
5502
5508
|
return result.pid;
|
|
@@ -5506,7 +5512,13 @@ async function launchOrRestart(mode) {
|
|
|
5506
5512
|
const { hotReloaded } = await restartService();
|
|
5507
5513
|
if (hotReloaded) return getServiceStatus().pid;
|
|
5508
5514
|
} else {
|
|
5509
|
-
await startService();
|
|
5515
|
+
const { started } = await startService(disabledBefore);
|
|
5516
|
+
if (!started) {
|
|
5517
|
+
throw new CliError("\u542F\u52A8\u5DF2\u53D6\u6D88\uFF1A\u671F\u95F4\u68C0\u6D4B\u5230 stop", {
|
|
5518
|
+
label: "\u542F\u52A8\u5931\u8D25",
|
|
5519
|
+
hint: ["\u53E6\u4E00\u4E2A\u7EC8\u7AEF\u5728\u672C\u6B21\u542F\u52A8\u8FC7\u7A0B\u4E2D\u6267\u884C\u4E86 mihomo stop\uFF0C\u5DF2\u6309\u6700\u540E\u4E00\u6761\u547D\u4EE4\u4FDD\u6301\u505C\u6B62\u3002", "", "\u786E\u5B9E\u8981\u542F\u52A8: mihomo start"]
|
|
5520
|
+
});
|
|
5521
|
+
}
|
|
5510
5522
|
}
|
|
5511
5523
|
return assertServiceHealthy();
|
|
5512
5524
|
}
|
|
@@ -6204,7 +6216,7 @@ async function cmdStart(args) {
|
|
|
6204
6216
|
const modeLabel = targetMode === "tun" ? "TUN" : "Mixed";
|
|
6205
6217
|
console.log([colors.cyan(modeLabel), sub.name, formatProxySummary(configInfo)].join(" \xB7 "));
|
|
6206
6218
|
try {
|
|
6207
|
-
const pid = await launchOrRestart(targetMode);
|
|
6219
|
+
const pid = await launchOrRestart(targetMode, serviceBefore.disabled);
|
|
6208
6220
|
console.log(`${colors.green("\u5DF2\u542F\u52A8")}${pid ? ` (PID ${pid})` : ""}`);
|
|
6209
6221
|
} catch (e) {
|
|
6210
6222
|
if (e instanceof CliError) throw e;
|