Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 13, 2025

Fixes EXC_BAD_ACCESS crash during realtime localization updates when UILabels refresh.

Problem

StringsLocalizationDataSource.findKey(for:) accessed the thread-safe strings property twice (lines 82, 86), creating two separate dictionary snapshots. Concurrent updates via update(with:) could modify the underlying data between these accesses, causing iteration over inconsistent state.

Changes

Thread Safety Fix

  • Cache strings property once per method call
  • Both for-loops now iterate over same consistent snapshot
  • Eliminates race condition while preserving existing concurrent queue guarantees
func findKey(for string: String) -> String? {
    // Get a consistent snapshot of strings to avoid thread safety issues
    let currentStrings = strings
    // Simple strings
    for (key, value) in currentStrings {
        if string == value { return key }
    }
    // Formated strings
    for (key, value) in currentStrings {
        // ... formatted string matching logic
    }
    return nil
}

Impact

  • Minimal change: +4/-2 lines in one file
  • PluralsLocalizationDataSource already follows this pattern correctly
Original prompt

Fix issue #349


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix issue #349 Fix race condition in StringsLocalizationDataSource.findKey causing EXC_BAD_ACCESS Nov 13, 2025
Copilot AI requested a review from andrii-bodnar November 13, 2025 14:42
Copilot finished work on behalf of andrii-bodnar November 13, 2025 14:42
@andrii-bodnar andrii-bodnar changed the title Fix race condition in StringsLocalizationDataSource.findKey causing EXC_BAD_ACCESS fix: race condition in StringsLocalizationDataSource.findKey causing EXC_BAD_ACCESS Nov 13, 2025
@andrii-bodnar
Copy link
Member

fixed in #350

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.

2 participants