Skip to content

fix(gateway): release platform locks on Slack/Signal connect failure - #5519

Closed
binhnt92 wants to merge 1 commit into
NousResearch:mainfrom
binhnt92:fix/slack-signal-lock-release-on-connect-failure
Closed

fix(gateway): release platform locks on Slack/Signal connect failure#5519
binhnt92 wants to merge 1 commit into
NousResearch:mainfrom
binhnt92:fix/slack-signal-lock-release-on-connect-failure

Conversation

@binhnt92

@binhnt92 binhnt92 commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

When Slack's connect() acquires a scoped lock on the app token and then fails (bad token, Socket Mode error, network issue), the lock is never released. The next hermes gateway restart sees "Slack app token already in use" and refuses to connect — the gateway is stuck until the process dies.

Same issue in Signal: if the health check fails after acquiring the phone lock, the lock is held permanently. The next start sees "Another local Hermes gateway is already using this Signal account" even with no other gateway running.

Changes Made

Slack (gateway/platforms/slack.py):

  • Added release_scoped_lock('slack-app-token', ...) in the except Exception block of connect()

Signal (gateway/platforms/signal.py):

  • Extracted inline lock release from disconnect() into reusable _release_phone_lock() helper
  • Added _release_phone_lock() + client.aclose() on both health check failure paths (non-200 and exception)

How to Test

python3 -m pytest tests/gateway/test_platform_lock_release.py -v

4 tests: Slack except block releases lock, Signal health check releases lock on both paths, Signal helper method exists, Signal closes httpx client on failure.

Checklist

  • Tests added (4 tests)
  • Full test suite run — no regressions
  • Tested on Linux (Ubuntu 22.04)

When Slack's connect() acquires a scoped lock on the app token and then
fails (bad token, Socket Mode error), the lock is never released. The
next gateway start sees "Slack app token already in use" and refuses to
connect until the process dies.

Same issue in Signal: if the health check fails after acquiring the
phone lock, the lock is held permanently.

Discord got this fix in PR NousResearch#5302. Slack and Signal were missed.

Add lock release to both exception/failure paths. Extract Signal's
inline release logic into a reusable _release_phone_lock() helper.
Also close the leaked httpx client on Signal health check failure.
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the fix, @binhnt92 — the lock-release behavior you identified is a real correctness issue and the analysis is solid.

This is an automated hermes-sweeper review.

Unfortunately this change was already landed by a different contributor before this PR could be merged:

  • Commit f23123e7bfix(gateway): prevent scoped lock and resource leaks on connection failure (Apr 19 2026) — ships the same finally-block pattern for Slack (gateway/platforms/slack.py lines 471-476) and Signal (gateway/platforms/signal.py lines 254-262), plus test coverage in tests/gateway/test_signal.py and tests/gateway/test_slack.py.

Current main already contains the fix, so closing as implemented.

@teknium1 teknium1 closed this Apr 27, 2026
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/slack Slack app adapter platform/signal Signal CLI adapter labels May 1, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #12916 (merged) — same fix: release scoped locks on Slack/Signal connect failure. That PR already addressed this in gateway/platforms/slack.py and gateway/platforms/signal.py.

@alt-glitch alt-glitch added the duplicate This issue or pull request already exists label May 1, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #12916 (merged)

1 similar comment
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #12916 (merged)

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

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists platform/signal Signal CLI adapter platform/slack Slack app adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants