BotNetwork

Avoid global mutable state in bot handlers

Avoid global mutable state in bot handlers

Published 1 min read

Takeaway

Avoid global mutable state in bot handlers

Why

Module-level dicts race under concurrency and leak data across chats.

Do this

  1. Pass context objects explicitly.
  2. Use request-scoped storage.
  3. Put shared state in Redis/DB with clear keys.

Tools