Skip to content

GET /gateway/bot timeout can lead to NoneType crash in client startup #243

@Alkapuce

Description

@Alkapuce

Summary

In qq-botpy 1.2.1, if GET https://api.sgroup.qq.com/gateway/bot times out during startup, the HTTP layer logs the timeout and returns None. Then client.py assumes the return value is a dict and immediately indexes self._ws_ap["session_start_limit"], causing:

TypeError: 'NoneType' object is not subscriptable

Observed Flow

Startup path:

  • client.start()
  • _bot_login()
  • self._ws_ap = await self.api.get_ws_url()
  • timeout happens in BotHttp.request()
  • timeout is logged, but no exception is raised to the caller
  • _bot_login() indexes self._ws_ap["session_start_limit"]

Relevant Behavior

In local source for qq-botpy 1.2.1:

botpy/http.py

  • catches asyncio.TimeoutError
  • logs 请求超时,请求连接: https://api.sgroup.qq.com/gateway/bot
  • returns None

botpy/client.py

  • immediately does:
self._ws_ap = await self.api.get_ws_url()
max_async = self._ws_ap["session_start_limit"]["max_concurrency"]

Actual Failure

请求超时,请求连接: https://api.sgroup.qq.com/gateway/bot
TypeError: 'NoneType' object is not subscriptable

Expected Behavior

One of these should happen instead:

  • retry transient timeout automatically
  • raise a clear exception from BotHttp.request() after retry budget is exhausted
  • validate /gateway/bot response before indexing and raise a structured startup error

Suggested Fix

At minimum:

  1. do not silently return None on timeout in BotHttp.request()
  2. either retry or raise an exception
  3. in _bot_login(), validate self._ws_ap before indexing session_start_limit

This would turn a transient network issue into a recoverable or at least diagnosable error, instead of an opaque NoneType crash.

Notes

This was observed in production usage via AstrBot 4.22.0 bundling qq-botpy 1.2.1, but the root cause appears to be in qq-botpy itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions