Skip to content

fix(server): WebSyncStore.mergeとWatchStateStoreのデッドロックを解消 - #42

Merged
HR0101 merged 3 commits into
mainfrom
fix/issue-40-websync-deadlock
Oct 29, 2026
Merged

HR0101 merged 3 commits into
mainfrom
fix/issue-40-websync-deadlock

Conversation

@HR0101

@HR0101 HR0101 commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Closes #40

概要

ブラウザUI等から連続して PUT /sync が送信された際、WebSyncStore.merge(incoming:) が保持するシリアルキュー(com.allserverformac.websync)と、メインスレッド上で動作する WatchStateStore.reload()(内部で WebSyncStore.snapshot() を同期呼び出し)が互いの完了を待ち合ってデッドロックし、Macアプリが無応答になる不具合(Issue #40)を修正しました。

原因と解決策

  • 原因:
    1. 1回目の PUT /sync の通知でメインスレッドが WatchStateStore.reload() → WebSyncStore.snapshot() に入り、websync キューの解放を待機
    2. 2回目の PUT /sync を処理中のワーカースレッドが、websync キューの queue.sync ブロック内で NotificationCenter.default.post を同期実行し、queue: .main のオブザーバー完了(メインスレッド)を待機
    3. メインスレッドと websync シリアルキューが相互待ち(デッドロック)となりアプリ全体が凍結
  • 解決策:
    1. WebSyncStore.merge(incoming:) での didChangeExternallyNotification 通知送出を queue.sync ブロックの外へ出し、websync キューを解放した後に DispatchQueue.main.async で非同期送出するよう変更
    2. WatchStateStore の NotificationCenter オブザーバー登録で queue: .main ではなく queue: nil を使用し、通知元スレッドでは Task { @MainActor [weak self] in self?.reload() } の投入のみを行ってメインスレッド完了を待たせないように変更
    3. 並行 merge とメインスレッドからの snapshot() 呼び出し・通知配信が互いにブロックしないことを検証する単体テスト(WebSyncStoreConcurrencyTests)を追加

機能・変更内容別コミット一覧

  1. 3c4eae7 - fix(server): WebSyncStore.mergeの外部変更通知をシリアルキュー解放後に非同期送出するよう修正
    • AllServerForMac/Features/Server/Services/WebSyncStore.swift
  2. 0b9f37c - fix(playback): WatchStateStoreの外部変更オブザーバーが通知元スレッドをブロックしないよう修正
    • AllServerForMac/Features/Playback/ViewModels/WatchStateStore.swift
  3. 8fa58e7 - test(server): WebSyncStore.mergeとWatchStateStoreの並行アクセス・デッドロック防止テストを追加
    • AllServerForMacTests/WebSyncStoreConcurrencyTests.swift

@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 953e9d8f-f846-4139-bd2e-12a5cbfc0e0b
  • Autofix · 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

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

@HR0101
HR0101 merged commit 7cc271b into main Oct 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Reliability] ブラウザUIの再生中にMacアプリがデッドロックして固まる(WebSyncStore.merge と WatchStateStore.reload)

1 participant