hermes - 💡(How to fix) Fix concurrency: _load_google_modules() TOCTOU — _google_modules_loaded set before imports complete

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

  1. Uses module globals (pubsub_v1, service_account, etc.) that are still their sentinel defaults (Any = Exception, None)

Fix Action

Fix

Double-checked locking: add import threading and _google_modules_lock = threading.Lock(), compute fully inside the lock, set GOOGLE_CHAT_AVAILABLE and all module globals, then set _google_modules_loaded = True last.

Code Example

if _google_modules_loaded:
    return GOOGLE_CHAT_AVAILABLE
_google_modules_loaded = True      # ← flag set here
try:
    import httplib2 as _httplib2   # ← imports happen here
    from google.cloud import pubsub_v1 as _pubsub_v1
    ...
GOOGLE_CHAT_AVAILABLE = True       # ← availability set last
RAW_BUFFERClick to expand / collapse

Bug

_load_google_modules() in plugins/platforms/google_chat/adapter.py sets _google_modules_loaded = True at line 95, before the actual import statements and before assigning the module globals.

if _google_modules_loaded:
    return GOOGLE_CHAT_AVAILABLE
_google_modules_loaded = True      # ← flag set here
try:
    import httplib2 as _httplib2   # ← imports happen here
    from google.cloud import pubsub_v1 as _pubsub_v1
    ...
GOOGLE_CHAT_AVAILABLE = True       # ← availability set last

A concurrent thread hitting the fast path after the flag write but before the imports complete:

  1. Sees _google_modules_loaded=True → early returns
  2. Returns GOOGLE_CHAT_AVAILABLE which is still False → Google Chat appears unavailable
  3. Uses module globals (pubsub_v1, service_account, etc.) that are still their sentinel defaults (Any = Exception, None)

The Google Chat gateway is called on every concurrent incoming message.

Fix

Double-checked locking: add import threading and _google_modules_lock = threading.Lock(), compute fully inside the lock, set GOOGLE_CHAT_AVAILABLE and all module globals, then set _google_modules_loaded = True last.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix concurrency: _load_google_modules() TOCTOU — _google_modules_loaded set before imports complete