fix(host): _read_loop 跳过非 dict JSON 消息,不再静默死亡
收到合法 JSON 但值不是 dict(如 ""、123、[]、null)时,
旧代码走到 msg.get('params') 抛 AttributeError/TypeError,
被外层 except 吞掉后读线程退出,此后所有 request() 等到超时。
现校验后记 stderr 日志并跳过,读循环继续;脏消息不进
events、不当正常请求处理。畸形 JSON 本已由 json.loads 的
except continue 处理,本次未改动该路径。
回归:tests/test_host_bugfix_host.py ReadLoopNonDictTest(2 项)
This commit is contained in:
1 parent
b9466e556b
commit
e768959c93
2 files changed
+98
No files matched your search
@@ -486,6 +486,20 @@ class Server:
|
||||
msg = json.loads(raw)
|
||||
except Exception:
|
||||
continue
|
||||
if not isinstance(msg, dict):
|
||||
# 非 dict 的合法 JSON(如 ""、123、[]、null):
|
||||
# 旧代码会走到下面的 msg.get("params") 抛
|
||||
# AttributeError/TypeError,被外层 except 吞掉
|
||||
# 后读线程退出,此后所有 request() 等到超时。
|
||||
# 脏消息只跳过、不当正常请求处理,读循环继续。
|
||||
try:
|
||||
sys.stderr.write(
|
||||
"host _read_loop: skip non-dict message "
|
||||
f"({type(msg).__name__}): {str(msg)[:200]}\n")
|
||||
sys.stderr.flush()
|
||||
except Exception:
|
||||
pass
|
||||
continue
|
||||
if "method" in msg and "id" in msg:
|
||||
self._answer_server_request(msg)
|
||||
continue
|
||||
|
||||
Reference in new issue
Block a user