mofeng-git / One-KVM

One-KVM,结合玩客云和PiKVM,实现低成本远控方案。
https://one-kvm.mofeng.run
Other
288 stars 28 forks source link

x86 系统上安装的 PiKVM VNC 无法连接 #30

Closed mofeng-git closed 1 day ago

mofeng-git commented 1 month ago

BUG 记录跟踪 反馈问题:x86 系统上使用本项目脚本安装 PiKVM,使用默认 VNC 配置,VNC 无法连接

关键日志:

kvmd.apps.vnc.rfb                ERROR --- [::ffff:223.104.63.227]:63983 [kvmd]: Unhandled exception
Traceback (most recent call last):
  File "/home/ubuntu/kvmd-master/kvmd/apps/vnc/rfb/__init__.py", line 118, in __wrapper
    await coro
  File "/home/ubuntu/kvmd-master/kvmd/apps/vnc/server.py", line 170, in __kvmd_task_loop
    async for (event_type, event) in self.__kvmd_ws.communicate():
  File "/home/ubuntu/kvmd-master/kvmd/clients/kvmd.py", line 163, in communicate
    yield htserver.parse_ws_event(msg.data)
  File "/home/ubuntu/kvmd-master/kvmd/htserver.py", line 244, in parse_ws_event
    raise RuntimeError("event must be a dict")
RuntimeError: event must be a dict
kvmd.apps.vnc.rfb                 INFO --- [::ffff:223.104.63.227]:63983 [main]: Cancelling subtask ...
kvmd.apps.vnc.rfb                 INFO --- [::ffff:223.104.63.227]:63983 [streamer]: Cancelling subtask ...
kvmd.apps.vnc.rfb                 INFO --- [::ffff:223.104.63.227]:63983 [fb_sender]: Cancelling subtask ...
kvmd.apps.vnc.rfb                 INFO --- [::ffff:223.104.63.227]:63983 [entry]: Connection closed
mofeng-git commented 1 month ago

复现环境:x86 系统使用本项目脚本正常安装 问题说明:有一处 Python 字典类型判断异常,转入异常处理,正常逻辑因此跳过。这里将 event 的内容打印出来再次进行字典类型判断通过,具体原因未知。 File "/home/ubuntu/kvmd-master/kvmd/htserver.py", line 244, in parse_ws_event

    event = data["event"]
    if not isinstance(event, dict):
        raise RuntimeError("event must be a dict")
    return (event_type, event)

event 的一个实例:

{'scheme': {'inputs': {}, 'outputs': {'long_button': {'switch': False, 'pulse': {'delay': 0.1, 'min_delay': 0.1, 'max_delay': 0.1}, 'hw': {'driver': 'long_press', 'pin': '0'}}, 'short_button': {'switch': False, 'pulse': {'delay': 0.1, 'min_delay': 0.1, 'max_delay': 0.1}, 'hw': {'driver': 'short_press', 'pin': '0'}}, 'wol_server1': {'switch': False, 'pulse': {'delay': 0.1, 'min_delay': 0.1, 'max_delay': 0.1}, 'hw': {'driver': 'wol_server1', 'pin': '0'}}}}, 'view': {'header': {'title': [{'type': 'label', 'text': '电源管理'}]}, 'table': [[{'type': 'label', 'text': '电源管理'}], None, [{'type': 'label', 'text': '短按(开/关机):'}, {'type': 'output', 'channel': 'short_button', 'confirm': False, 'text': '按下'}], [{'type': 'label', 'text': '长按(强制关机):'}, {'type': 'output', 'channel': 'long_button', 'confirm': False, 'text': '按下'}], None, [{'type': 'label', 'text': '网络唤醒'}], [{'type': 'label', 'text': '被控机设备'}, {'type': 'output', 'channel': 'wol_server1', 'confirm': False, 'text': '网络唤醒'}]]}}
{'keymaps': {'default': 'en-us', 'available': ['ar', 'bepo', 'cz', 'da', 'de', 'de-ch', 'en-gb', 'en-us', 'en-us-altgr-intl', 'es', 'et', 'fi', 'fo', 'fr', 'fr-be', 'fr-ca', 'fr-ch', 'hr', 'hu', 'is', 'it', 'ja', 'lt', 'lv', 'mk', 'nl', 'no', 'pl', 'pt', 'pt-br', 'ru', 'sl', 'sv', 'th', 'tr']}}
{'ocr': {'enabled': True, 'langs': {'default': ['eng'], 'available': ['eng', 'osd']}}}
{'enabled': True}
{'janus_static': {'name': 'Janus Static', 'description': 'Janus WebRTC Gateway (Static Config)', 'path': 'janus', 'daemon': 'kvmd-janus-static', 'place': -1, 'enabled': True, 'started': True}, 'janus': {'name': 'Janus', 'description': 'Janus WebRTC Gateway', 'path': 'janus', 'daemon': 'kvmd-janus', 'place': -1, 'enabled': False, 'started': False}, 'ipmi': {'name': 'IPMI', 'description': 'Show IPMI information', 'icon': 'share/svg/ipmi.svg', 'path': 'ipmi', 'daemon': 'kvmd-ipmi', 'port': 623, 'place': 21, 'enabled': True, 'started': True}, 'vnc': {'name': 'VNC', 'description': 'Show VNC information', 'icon': 'share/svg/vnc.svg', 'path': 'vnc', 'daemon': 'kvmd-vnc', 'port': 5900, 'place': 20, 'enabled': True, 'started': False}, 'webterm': {'name': 'Terminal', 'description': 'Open terminal in a web browser', 'icon': 'extras/webterm/terminal.svg', 'path': 'extras/webterm/ttyd', 'daemon': 'kvmd-webterm', 'place': 10, 'enabled': False, 'started': False}}
{'monitored': False, 'state': None}
None
{'server': {'host': 'VM-8-17-ubuntu'}, 'kvm': {}}
{'kvmd': {'version': '4.3'}, 'streamer': {'app': 'ustreamer', 'version': '4.9', 'features': {'WITH_OMX': False, 'WITH_GPIO': False, 'WITH_PTHREAD_NP': True, 'WITH_SETPROCTITLE': True, 'HAS_PDEATHSIG': True}}, 'kernel': {'system': 'Linux', 'release': '5.15.0-106-generic', 'version': '#116-Ubuntu SMP Wed Apr 17 09:17:56 UTC 2024', 'machine': 'x86_64'}}
{'inputs': {}, 'outputs': {'long_button': {'online': True, 'state': False, 'busy': False}, 'short_button': {'online': True, 'state': False, 'busy': False}, 'wol_server1': {'online': True, 'state': False, 'busy': False}}}
{'online': 0, 'busy': False, 'connected': None, 'keyboard': {'online': 0, 'leds': {'num': False, 'caps': False, 'scroll': False}, 'outputs': {'available': [], 'active': ''}}, 'mouse': {'online': 0, 'absolute': True, 'outputs': {'available': ['usb', 'usb_rel'], 'active': 'usb'}}, 'jiggler': {'enabled': False, 'active': False, 'interval': 60}}
{'enabled': False, 'busy': False, 'leds': {'power': False, 'hdd': False}}
{'enabled': False, 'online': False, 'busy': False, 'storage': None, 'drive': None}
{'limits': {'desired_fps': {'min': 0, 'max': 70}, 'available_resolutions': ['1080x720']}, 'params': {'desired_fps': 30, 'resolution': '1280x720'}, 'snapshot': {'saved': None}, 'streamer': None, 'features': {'quality': False, 'resolution': True, 'h264': False}}
{}
{'limits': {'desired_fps': {'min': 0, 'max': 70}, 'available_resolutions': ['1080x720']}, 'params': {'desired_fps': 30, 'resolution': '1280x720'}, 'snapshot': {'saved': None}, 'streamer': {'encoder': {'type': 'CPU', 'quality': 80}, 'source': {'resolution': {'width': 640, 'height': 480}, 'online': False, 'desired_fps': 30, 'captured_fps': 0}, 'stream': {'queued_fps': 0, 'clients': 0, 'clients_stat': {}}}, 'features': {'quality': False, 'resolution': True, 'h264': False}}

其他:在 PiKVM 官方主程序代码运行此测试没有出现问题。

mofeng-git commented 1 month ago

暂时解决办法:修改文件跳过字典判断 编辑文件 /usr/lib/python3.11/site-packages/kvmd/htserver.py,注释第244行,再增加一行添加内容 return (event_type, event) 到第245行,注意保持同样缩进。最后有两行内容一样缩进不同的代码是没有问题的。 最然后重启 kvmd kvmd-vnc 服务此问题就不会再出现了。

    event = data["event"]
    if not isinstance(event, dict):
        #raise RuntimeError("event must be a dict")
        return (event_type, event)
    return (event_type, event)

图片

mofeng-git commented 1 day ago

问题废弃,Docker 版本的 VNC 服务可以正常运行