brave / brave-browser

Brave browser for Android, iOS, Linux, macOS, Windows.
https://brave.com
Mozilla Public License 2.0
17.84k stars 2.33k forks source link

Sometimes iOS crashes when loading web pages that would block ads #36952

Closed kylehickinson closed 7 months ago

kylehickinson commented 7 months ago

Description:

EXC_BAD_ACCESS (code=1, address=0xbeaddc390310)

Thread 61 Queue : com.apple.root.user-initiated-qos.cooperative (concurrent)
#0  0x000000018005f008 in objc_msgSend ()
#1  0x000000018051e514 in -[__NSDictionaryM setObject:forKey:] ()
#2  0x0000000180af46cc in NSMutableDictionary.subscript.setter ()
#3  0x0000000180af461c in @objc NSMutableDictionary.subscript.setter ()
#4  0x000000010317e0d0 in FifoDict.addElement(_:forKey:) at /src/brave/ios/brave-ios/Sources/Brave/WebFilters/ShieldStats/Adblock/FifoDict.swift:25
#5  0x00000001031769c4 in CachedAdBlockEngine.shouldBlock(requestURL:sourceURL:resourceType:isAggressiveMode:) at /src/brave/ios/brave-ios/Sources/Brave/WebFilters/ShieldStats/Adblock/CachedAdBlockEngine.swift:132
#6  0x000000010316ed7c in closure #1 in AdBlockStats.shouldBlock(requestURL:sourceURL:resourceType:isAggressiveMode:) at /src/brave/ios/brave-ios/Sources/Brave/WebFilters/ShieldStats/Adblock/AdBlockStats.swift:224
#7  0x0000000103171b64 in partial apply for closure #1 in AdBlockStats.shouldBlock(requestURL:sourceURL:resourceType:isAggressiveMode:) ()
#8  0x0000000103210898 in closure #1 in closure #1 in Sequence.asyncConcurrentMap<τ_0_0>(_:) at /src/brave/ios/brave-ios/Sources/BraveShared/Extensions/AsyncAwait.swift:38
#9  0x0000000103216f58 in partial apply for closure #1 in closure #1 in Sequence.asyncConcurrentMap<τ_0_0>(_:) ()

Most likely a threading issue, FifoDict access should be behind a lock or serial queue

Steps to Reproduce

  1. Load a web page that may block ads and count towards adblock stats

Actual result:

Crashes

Expected result:

Reproduces how often:

Intermittent

Brave Version:

A regression caused by https://github.com/brave/brave-core/pull/21883 so latest nightlys that include this change

hffvld commented 5 months ago

Verified on iPhone 14 using version(s):

Device/OS: iPhone 14 / iOS 17.5
Brave build: 1.66 (110)
BraveCore: 1.66.110 (125.0.6422.60)

STEPS:

  1. Follow the steps from https://github.com/brave/brave-browser/issues/36952#issue-2197735000
  2. Verify

ACTUAL RESULTS:


https://github.com/brave/brave-browser/assets/128532965/eb1f4ec3-44f0-4bbe-a3ca-3a3021347a3b