Repository navigation
fix(server): WebSyncStore.mergeとWatchStateStoreのデッドロックを解消 - #42
Merged
Merged
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #40
概要
ブラウザUI等から連続して
PUT /syncが送信された際、WebSyncStore.merge(incoming:)が保持するシリアルキュー(com.allserverformac.websync)と、メインスレッド上で動作するWatchStateStore.reload()(内部でWebSyncStore.snapshot()を同期呼び出し)が互いの完了を待ち合ってデッドロックし、Macアプリが無応答になる不具合(Issue #40)を修正しました。原因と解決策
PUT /syncの通知でメインスレッドがWatchStateStore.reload()→WebSyncStore.snapshot()に入り、websyncキューの解放を待機PUT /syncを処理中のワーカースレッドが、websyncキューのqueue.syncブロック内でNotificationCenter.default.postを同期実行し、queue: .mainのオブザーバー完了(メインスレッド)を待機websyncシリアルキューが相互待ち(デッドロック)となりアプリ全体が凍結WebSyncStore.merge(incoming:)でのdidChangeExternallyNotification通知送出をqueue.syncブロックの外へ出し、websyncキューを解放した後にDispatchQueue.main.asyncで非同期送出するよう変更WatchStateStoreのNotificationCenterオブザーバー登録でqueue: .mainではなくqueue: nilを使用し、通知元スレッドではTask { @MainActor [weak self] in self?.reload() }の投入のみを行ってメインスレッド完了を待たせないように変更mergeとメインスレッドからのsnapshot()呼び出し・通知配信が互いにブロックしないことを検証する単体テスト(WebSyncStoreConcurrencyTests)を追加機能・変更内容別コミット一覧
3c4eae7-fix(server): WebSyncStore.mergeの外部変更通知をシリアルキュー解放後に非同期送出するよう修正AllServerForMac/Features/Server/Services/WebSyncStore.swift0b9f37c-fix(playback): WatchStateStoreの外部変更オブザーバーが通知元スレッドをブロックしないよう修正AllServerForMac/Features/Playback/ViewModels/WatchStateStore.swift8fa58e7-test(server): WebSyncStore.mergeとWatchStateStoreの並行アクセス・デッドロック防止テストを追加AllServerForMacTests/WebSyncStoreConcurrencyTests.swift