Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/Swift/HangTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ final class DefaultHangTracker<T: RunLoopObserver> {
mainQueueState = .init()
}

// It's safe to access mainQueueState here regardless of the thread
// because this is the only reference to `self` while
// it is being deallocated.
deinit {
guard let observer = mainQueueState.observer else {
return
Expand Down
8 changes: 8 additions & 0 deletions Tests/SentryTests/Integrations/ANR/HangTrackerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ final class HangTrackerTests: XCTestCase {

sut = nil

// Allow the hang tracker's background thread to finish since it holds
// a strong reference while it is running
let expectation = XCTestExpectation()
queue.async {
expectation.fulfill()
}
wait(for: [expectation])

XCTAssertNil(weakSut, "Expected observer to be deallocated")
}

Expand Down
Loading