Skip to content

Fix: avoid QQ Gateway receive timeout - #233

Open
shoucandanghehe wants to merge 2 commits into
nonebot:masterfrom
shoucandanghehe:fix/websocket-receive-timeout
Open

Fix: avoid QQ Gateway receive timeout#233
shoucandanghehe wants to merge 2 commits into
nonebot:masterfrom
shoucandanghehe:fix/websocket-receive-timeout

Conversation

@shoucandanghehe

Copy link
Copy Markdown
Member

Summary

  • use a granular timeout for the QQ Gateway WebSocket connection
  • disable the receive idle timeout while preserving 30-second connect and close limits
  • add a regression test at the Driver Request seam

Problem

Since NoneBot2 2.5.0, the aiohttp Driver maps Request(timeout=30.0) to both ws_receive=30 and ws_close=30, while the websockets Driver maps the same value to open and close timeouts.

The QQ Gateway can remain idle for longer than 30 seconds. With the aiohttp Driver, this raises TimeoutError and makes the adapter reconnect every 30 seconds, delaying event delivery.

Related behavior was introduced by nonebot/nonebot2#3923.

Solution

Use an explicit Timeout:

  • connect=30.0
  • read=None
  • close=30.0

This preserves bounded connection setup and shutdown without applying an idle timeout to the long-lived receive loop.

Verification

  • regression test failed before the fix because the Gateway Request carried the scalar 30.0
  • uv run pytest on Python 3.14: 6 passed
  • uv run --python 3.10 pytest: 6 passed
  • Ruff checks passed
  • patched adapter with the real QQ sandbox Gateway and aiohttp remained connected for 85 seconds without reconnecting; the previous code reconnected after exactly 30 seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant