[Bug] MuMu12:shutdown_player 后立即 launch_player 的启动请求被残留的 MuMuNxMain 单例静默吞掉,导致 "Emulator start timeout"

Author: ERICHZYMK1Created Sep 15, 2026Updated Sep 15, 2026

环境信息

  • ALAS:master 分支 92c07aa28ba8515b7709542ae8c14f6a7f3a08bd(AlasApp_0.4.4_fullcn 整合包,AutoUpdate 于 2026-09-15 拉取到最新)
  • 系统:Windows 11 x64 (build 26200)
  • 模拟器:MuMu 12("MuMu模拟器" 5.23.0.3181),实例 0,serial 127.0.0.1:16384,路径 D:\mumu\MuMuPlayer-12.0
  • 触发场景:模拟器刚被手动关闭(或处于半退出状态)后,由 ALAS 调度自动启动模拟器

现象

调度自动运行任务时,ALAS 尝试拉起 MuMu12,emulator_start() 三次重试全部失败,期间模拟器窗口从未出现;而同一状态下在 GUI 手动点"启动"(稍晚几分钟执行)则能正常拉起模拟器。日志特征为连续的 EMULATOR START → shutdown_player → launch_player → (约180秒后) Emulator start timeout

log
2026-09-15 20:04:45.455 | INFO | [customer.network_bridge_opened] false
2026-09-15 20:04:45.457 | WARNING | No such device exists, please restart the emulator or set a correct serial
2026-09-15 20:04:45.466 | INFO | EMULATOR START
2026-09-15 20:04:45.484 | INFO | Execute: "D:/mumu/MuMuPlayer-12.0/nx_main/MuMuManager.exe" api -v 0 shutdown_player
2026-09-15 20:04:45.496 | INFO | Execute: "D:/mumu/MuMuPlayer-12.0/nx_main/MuMuManager.exe" api -v 0 launch_player
2026-09-15 20:07:46.906 | WARNING | Emulator start timeout
2026-09-15 20:07:46.915 | INFO | Execute: ".../MuMuManager.exe" api -v 0 launch_player
2026-09-15 20:10:05.957 | WARNING | No such device exists, please restart the emulator or set a correct serial
2026-09-15 20:10:05.974 | INFO | Execute: ".../MuMuManager.exe" api -v 0 launch_player
2026-09-15 20:13:14.832 | WARNING | No such device exists, please restart the emulator or set a correct serial
2026-09-15 20:13:14.848 | INFO | Execute: ".../MuMuManager.exe" api -v 0 launch_player
(gui 日志:20:13:08 [alas] exited / 20:13:25 [alas] exited —— 两次调度运行均因启动失败退出)

根因:本机命令行实验复现

对照组(干净状态,直接 launch):MuMu 未运行时直接执行 MuMuManager.exe api -v 0 launch_player,约 30 秒内 MuMuNxMain / MuMuVMMHeadless 正常出现,ADB 端口 16384 开始监听。成功

实验组(复刻 ALAS 的 stop→start 序列):模拟器正在运行时依次执行:

MuMuManager.exe api -v 0 shutdown_player
MuMuManager.exe api -v 0 launch_player   (与上一条间隔 <100ms)

结果:

  1. shutdown_player 只打印了 current select player index: 0没有输出任何 result 行,命令最终以 0xC0000005(Access Violation)退出——崩溃发生在 MuMuManager.exe 内部;
  2. 虚拟机进程 MuMuVMMHeadless.exe 退出(shutdown 生效),但 MuMuNxMain.exe 残留为僵尸单例
  3. 紧随的 launch_player 打印 player launch: result=0但模拟器并没有启动——等待 45 秒以上,MuMuVMMHeadless 始终未出现、ADB 端口 16384 无监听。启动请求被半死的 MuMuNxMain 单例吞掉,即 platform_windows.py 注释中已描述的 "silently dropped" 机制;
  4. 稍后(后台状态恢复后)再次执行同样的 launch_player:正常拉起,成功

即:问题不在于 launch 本身不可用,而在于 stop 后立即 start 的组合在"实例半退出"状态下必然失败,且失败对 ALAS 完全不可见。

放大问题的 ALAS 侧因素

  1. emulator_start()(module/device/platform/platform_windows.py)每次重试都无条件先 stop 再 start,即使设备本来就不在线;两者实际间隔仅约 10ms;
  2. execute() 使用 subprocess.Popen(...) 丢弃了 MuMuManager 的 stdout/stderr,shutdown_player 崩溃(0xC0000005)和 launch 被吞(result=0 但未生效)在 ALAS 日志中完全不可见,只能盲等 180 秒超时;
  3. 3 次重试重复完全相同的坏序列,在上述状态下必然全部失败,最终任务运行直接退出([alas] exited)。

建议修复方向

  1. 捕获 MuMuManager 输出:execute() 针对命令行管理工具(MuMuManager/ldconsole 等)用 subprocess.run(capture_output=True) 或 Popen+communicate 将输出写入日志。即使不改动启动逻辑,这一条也能让今后所有此类问题可直接诊断;
  2. stop 与 start 之间加入确认:MuMu12 的 shutdown 后轮询实例状态(MuMuManager 查询接口或 ADB 端口消失)再 launch,或直接加数秒间隔;
  3. launch 前清理僵尸单例:检测到 MuMuNxMain.exe 存在但无对应 MuMuVMMHeadless(实例实际未运行)时,先 taskkill 再 launch;
  4. start 前先判断设备是否已在线:设备在线时跳过 stop,避免"本来想重启结果把好实例弄成僵尸"。

临时规避(本人当前使用)

绕开 ALAS 内部启动路径:外部脚本在启动 ALAS 前先 taskkill 残留的 MuMuNxMain.exe,直接执行 launch_player(不先 shutdown),轮询 ADB 端口 16384 就绪后再启动 ALAS。实测多次稳定。


以下为更完整的 log 文件: 2026-09-15_alas.txt

Source: LmeSzinc/AzurLaneAutoScript