Skip to content

fix(backend): Redis接続復旧時に必要な購読を復元する - #74

Merged
mattyatea merged 1 commit into
developfrom
codex/fix-redis-subscription-recovery
Oct 6, 2026
Merged

mattyatea merged 1 commit into
developfrom
codex/fix-redis-subscription-recovery

Conversation

@mattyatea

Copy link
Copy Markdown

What

Redis購読専用接続がreadyになるたびにホストのSUBSCRIBEを発行し、初回接続失敗後と確立済み購読の再接続後にイベント受信を復元します。
購読の発行元をこの処理に統一するためautoResubscribeを無効にし、SUBSCRIBEの失敗はログへ出します。

Why

Closes #73

起動時に一度だけ発行したSUBSCRIBEは、接続障害がioredisの再試行上限を超えると破棄されます。
成功応答前は自動再購読の登録がないため、接続だけ復旧してイベント配信が停止したままになります。
修正前の実際のproviderとioredis 5.11.1で、MaxRetriesPerRequestErrorの未処理と復旧後の購読者0を再現しました。

Additional info (optional)

使い捨てのローカルRedis 7とTCPプロキシで、初回接続が再試行上限を超える場合と、確立済み購読を切断した場合の両方を検証しました。
各ケースで復旧後のPUBLISHに購読者1が返り、実際のメッセージ受信を確認しています。
テストは専用channel・専用購読接続だけを遮断します。

検証済み:

  • pnpm --filter backend test --run test/unit/GlobalModule.ts(backendビルドと2テスト成功)
  • pnpm --filter backend typecheck(src / test / test-federation成功)
  • node scripts/check-shipping.mjs --base origin/develop(変更ファイルlint / SPDX / locale safety成功)
  • package rootからpnpm exec eslint --quiet test/unit/GlobalModule.ts(成功)

healthの判定、ブラウザー側、本番watchdogは変更していません。
本番への障害注入・デプロイと、変更後の実環境WebSocket E2Eは未実施です。
本番で初回SUBSCRIBEが失敗した直接ログは未取得であり、今回確定したのはローカルでのコード経路の再現です。
API・entity・migrationの変更がないためSDK再生成・migration検査は対象外です。
CHANGELOGは未変更で、候補は「Redis接続復旧後に購読が復元されずリアルタイム配信が停止する問題を修正」です。

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

Copilot AI balanced review requested due to automatic review settings October 6, 2026 07:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: Type4ny-Project/Misskey/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 45278734-8343-406a-a8da-fb4b953d4e2a
📥 Commits

Reviewing files that changed from the base of the PR and between 661244c and 0d0a83a.

📒 Files selected for processing (2)
  • packages/backend/src/GlobalModule.ts
  • packages/backend/test/unit/GlobalModule.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Redis購読クライアントは自動再購読を無効にし、接続のreadyイベントごとにホストを購読します。テストでは、初回接続に失敗した場合と確立済みの接続が切断された場合に、接続復旧後のメッセージ受信を確認します。

Changes

Redis購読の復旧

Layer / File(s) Summary
接続時の購読処理と復旧テスト
packages/backend/src/GlobalModule.ts, packages/backend/test/unit/GlobalModule.ts
$redisForSubのautoResubscribeを無効にし、readyイベントごとにconfig.hostを購読します。購読失敗時はエラーを記録します。テストでは初回接続失敗後と確立済み接続の切断後に、接続を復旧してメッセージを受信できることを検証します。

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 0d0a8

The change restores host Redis subscriptions whenever the connection becomes ready, covering both a failed initial connection and a dropped connection. No regression was found. The remaining case is a SUBSCRIBE that Redis rejects while the connection stays open. That case already behaved the same way before this change and is not addressed by this PR. The change appears ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed タイトルは、Redis接続の復旧時に必要な購読を復元するという主な変更を明確に示しています。
Description check ✅ Passed 「What」「Why」「Additional info」「Checklist」があり、変更内容、目的、テスト結果、未実施の検証項目を具体的に記載しています。
Linked Issues check ✅ Passed Issue #73 は、初回 SUBSCRIBE 失敗後と確立済み購読の切断後に、購読を復元してイベントを受信することを求めています。packages/backend/src/GlobalModule.ts は購読専用 Redis 接続の ready ごとに config.host を購読し、autoResubscribe を無効にして購読元を一本化し、失敗をログへ記録します。`p…
Out of Scope Changes check ✅ Passed 変更は Issue #73 の Redis 購読復旧処理と、その初回失敗・再接続を検証するテストに限定されています。無関係な変更は確認されません。
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Redisが目覚めて、購読を始めます
接続が戻れば、またチャンネルへ
届くメッセージを、テストで確認
切れてもつながり、声が届きます
readyの合図で、購読が復旧します

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

このPRによるapi.jsonの差分
差分はありません。
Get diff files from Workflow Page

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

🖥 Frontend Diagnostics Report

(No significant changes)

View details

Requests by resource type
Type Requests Encoded bytes
Base Head Δ Base Head Δ
Document 2 2 0 34 KB 34 KB 0 B
Script 151 151 0 2.4 MB 2.4 MB $\color{green}{\text{-1.4 KB}}$
Stylesheet 63 63 0 320 KB 320 KB 0 B
Fetch 28 28 0 47 KB 47 KB 0 B
Image 9 9 0 238 KB 238 KB 0 B
Font 2 2 0 129 KB 129 KB 0 B
Other 9 9 0 421 KB 421 KB $\color{green}{\text{-1 B}}$
V8 heap snapshot statistics
Metric @ Base @ Head Δ MAD
$\color{gray}{\rule{8pt}{8pt}}$ Total 12 MB
± 4 KB
12 MB
± 3.5 KB
$\text{-11 KB}$
$\text{-0.1\%}$
5.3 KB
$\color{orange}{\rule{8pt}{8pt}}$ Code 3 MB 3 MB $\text{-936 B}$ 1.3 KB
$\color{red}{\rule{8pt}{8pt}}$ Strings 1.3 MB 1.3 MB $\text{+88 B}$ 217 B
$\color{cyan}{\rule{8pt}{8pt}}$ JS arrays 121 KB 121 KB 0 B 0 B
$\color{green}{\rule{8pt}{8pt}}$ Typed arrays 0 B 0 B 0 B 0 B
$\color{yellow}{\rule{8pt}{8pt}}$ System objects 0 B 0 B 0 B 0 B
$\color{violet}{\rule{8pt}{8pt}}$ Other JS objs 2.1 MB 2.1 MB $\text{-552 B}$ 397 B
$\color{pink}{\rule{8pt}{8pt}}$ Other non-JS objs 5.4 MB 5.4 MB $\text{-5.1 KB}$ 6.9 KB

Download representative heap snapshot: base / head

📦 Bundle Stats

Chunk size diff (0 updated, 0 added, 0 removed)
Chunk Base Head Δ Δ (%)
(total) 6.1 MB 6.1 MB $\text{-704 B}$ $\text{-0\%}$
(other generated chunks) 2.3 MB 2.3 MB $\text{-704 B}$ $\text{-0\%}$
Startup chunk size (0 updated, 0 added, 0 removed)
Chunk Base Head Δ Δ (%)
(total) 941 KB 940 KB $\text{-704 B}$ $\text{-0.1\%}$
(other generated chunks) 867 KB 866 KB $\text{-704 B}$ $\text{-0.1\%}$
(other) 74 KB 74 KB 0 B 0%

Startup chunks are the Vite entry for src/_boot_.ts and its static imports.

Bundles Modules Entries Imports Size
Static Dynamic Rendered Gzip Brotli
Base 505 3,007 22 11,222 364 11 MB 3 MB 2.6 MB
Head 505 3,007 22 11,222 364 11 MB 3 MB 2.6 MB
Δ 0 0 0 0 0 $\color{green}{\text{-1.6 KB}}$ $\text{-272 B}$ $\text{-139 B}$
Δ (%) 0% 0% 0% 0% 0% $\text{-0\%}$ $\text{-0\%}$ $\text{-0\%}$

Open treemap HTML

@mattyatea
mattyatea merged commit 0ecf33e into develop Oct 6, 2026
39 checks passed
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

⚙️ Backend Diagnostics Report

Memory: After GC

(No significant changes)

V8 Heap Snapshot Statistics

Metric @ Base @ Head Δ MAD
$\color{gray}{\rule{8pt}{8pt}}$ Total 90 MB
± 3.2 KB
90 MB
± 10 KB
$\text{-15 KB}$
$\text{-0\%}$
11 KB
$\color{orange}{\rule{8pt}{8pt}}$ Code 26 MB 26 MB $\text{-2.1 KB}$ 7.2 KB
$\color{red}{\rule{8pt}{8pt}}$ Strings 31 MB 31 MB $\text{-3.6 KB}$ 710 B
$\color{cyan}{\rule{8pt}{8pt}}$ JS arrays 4.9 MB 4.9 MB 0 B 0 B
$\color{green}{\rule{8pt}{8pt}}$ Typed arrays 566 KB 566 KB 0 B 0 B
$\color{yellow}{\rule{8pt}{8pt}}$ System objects 2.3 MB 2.3 MB $\text{+1.5 KB}$ 1.4 KB
$\color{violet}{\rule{8pt}{8pt}}$ Other JS objs 25 MB 25 MB $\text{-120 B}$ 1.1 KB
$\color{pink}{\rule{8pt}{8pt}}$ Other non-JS objs 39 KB 39 KB 0 B 0 B

Download representative heap snapshot: base / head

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Redis初回購読失敗後にイベント配信が復旧しない

2 participants