Fix: replace lock(this) with static per-file-path lock#18
Open
HashidaTKS wants to merge 1 commit into
Open
Conversation
…a corruption lock(this) only protects against concurrent access from the same instance. When multiple instances access the same file (as seen in RaceDataManager and AutoPurchaserMainTask), there is no mutual exclusion, risking file corruption. Introduce a static Dictionary<string, object> keyed by file path in XmlSerializerWrapper so that all instances targeting the same file share one lock object. Remove the now-redundant lock(this) in BaseRepository. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
問題点
BaseRepositoryおよびXmlSerializerWrapperでlock(this)を使用していたため、同一ファイルに対して複数のインスタンスが同時アクセスした場合に排他制御が機能しなかった。具体的には
RaceDataManager.csやAutoPurchaserMainTask.csでnew HoldingInformationRepository()が複数回呼ばれており、UIスレッドとバックグラウンドタスクが同時に同じXMLファイルを読み書きするとファイル破損やデシリアライズ失敗が発生しうる状態だった。改善内容
XmlSerializerWrapperにファイルパスをキーとしたstatic Dictionary<string, object> _fileLocksを追加lock(this)をlock(GetFileLock())に置き換え、同一ファイルパスへのアクセスはインスタンスをまたいで排他制御されるよう修正BaseRepository側の冗長なlock(this)を削除(XmlSerializerWrapper側で保護されるため)Test plan
Store/ReadAllを呼んだ際にデータ破損が起きないことを確認🤖 Generated with Claude Code