Skip to content

Commit

Permalink
Merge branch 'main' into armcknight/fix/possible-nil-crash
Browse files Browse the repository at this point in the history
  • Loading branch information
brustolin authored Apr 14, 2023
2 parents 965a077 + 3b782cc commit 8e23a00
Show file tree
Hide file tree
Showing 58 changed files with 447 additions and 442 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@04df1262e6247151b5ac09cd2c303ac36ad3f62b # pin@v2
uses: github/codeql-action/init@d186a2a36cc67bfa1b860e6170d37fb9634742c7 # pin@v2
with:
languages: ${{ matrix.language }}

Expand All @@ -35,4 +35,4 @@ jobs:
-destination platform="iOS Simulator,OS=latest,name=iPhone 11 Pro"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@04df1262e6247151b5ac09cd2c303ac36ad3f62b # pin@v2
uses: github/codeql-action/analyze@d186a2a36cc67bfa1b860e6170d37fb9634742c7 # pin@v2
8 changes: 7 additions & 1 deletion .github/workflows/saucelabs-UI-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
xcode: '13.4.1'

- runs-on: macos-12
xcode: '14.1'
xcode: '14.2'

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -93,6 +93,9 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: '14.2'
suite: 'iOS-16'

- xcode: '13.4.1'
suite: 'iOS-15'

Expand All @@ -106,6 +109,9 @@ jobs:
- xcode: '13.4.1'
suite: 'iOS-13'

- xcode: '13.4.1'
suite: 'iOS-12'

steps:
- uses: actions/checkout@v3

Expand Down
61 changes: 14 additions & 47 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ jobs:
# we get the error 'XCTest/XCTest.h' not found. Setting ENABLE_TESTING_SEARCH_PATH=YES
# doesn't work.
include:
# iOS 12.4
- runs-on: macos-11
platform: 'iOS'
xcode: '13.2.1'
test-destination-os: '12.4'
# This job needs to install the simulator which can take a couple of minutes
timeout-minutes: 25

# iOS 13.7
- runs-on: macos-11
Expand Down Expand Up @@ -130,6 +123,13 @@ jobs:
xcode: '13.4.1'
test-destination-os: 'latest'
timeout-minutes: 15

# macOS 13
- runs-on: macos-12
platform: 'macOS'
xcode: '14.2'
test-destination-os: 'latest'
timeout-minutes: 15

# Catalyst. We only test the latest version, as
# the risk something breaking on Catalyst and not
Expand All @@ -156,6 +156,13 @@ jobs:
test-destination-os: 'latest'
timeout-minutes: 15

# tvOS 16
- runs-on: macos-12
platform: 'tvOS'
xcode: '14.2'
test-destination-os: 'latest'
timeout-minutes: 15

steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
Expand All @@ -167,14 +174,6 @@ jobs:

- run: ./scripts/ci-select-xcode.sh ${{matrix.xcode}}

# GH action images don't have an iOS 12.4 simulator. Therefore we have to download and install the simulator manually.
- name: Install iOS 12.4 simulator
if: ${{ matrix.platform == 'iOS' && matrix.test-destination-os == '12.4'}}
run: |
gem install xcode-install
xcversion simulators --install='iOS 12.4'
xcrun simctl create custom-test-device "iPhone 8" "com.apple.CoreSimulator.SimRuntime.iOS-12-4"
# Workaround with a symlink pointed out in: https://github.com/actions/virtual-environments/issues/551#issuecomment-637344435
- name: Prepare iOS 13.7 simulator
if: ${{ matrix.platform == 'iOS' && matrix.test-destination-os == '13.7'}}
Expand Down Expand Up @@ -326,38 +325,6 @@ jobs:
~/Library/Logs/scan/*.log
./fastlane/test_output/**
# macos-11 doesn't have a simulator for iOS 12
ui-tests-swift-ios-12:
name: UI Tests on iOS 12 Simulator
runs-on: macos-11
strategy:
matrix:
target: ['ios_swift', 'ios_objc', 'tvos_swift']

steps:
- uses: actions/checkout@v3

# GH action images don't have an iOS 12.4 simulator. Therefore we have to download and install the simulator manually.
- name: Install iOS 12.4 simulator
run: |
gem install xcode-install
xcversion simulators --install='iOS 12.4'
xcrun simctl create custom-test-device "iPhone 8" "com.apple.CoreSimulator.SimRuntime.iOS-12-4"
# GitHub Actions sometimes fail to launch the UI tests. Therefore we retry
- name: Run Fastlane
run: for i in {1..2}; do fastlane ui_tests_${{matrix.target}} device:"iPhone 8 (12.4)" address_sanitizer:false && break ; done
shell: sh

- name: Archiving Raw Test Logs
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: raw-uitest-output-${{matrix.target}}-ios-12
path: |
~/Library/Logs/scan/*.log
./fastlane/test_output/**
ui-tests-address-sanitizer:
name: UI Tests with Address Sanitizer
runs-on: macos-12
Expand Down
7 changes: 6 additions & 1 deletion .sauce/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ xcuitest:
testApp: ./DerivedData/Build/Products/Test-iphoneos/iOS-SwiftUITests-Runner.app

suites:

- name: "iOS-16"
devices:
- name: "iPhone.*"
platformVersion: "16.4"

- name: "iOS-15"
devices:
Expand All @@ -36,7 +41,7 @@ suites:
- name: "iOS-12"
devices:
- name: "iPhone.*"
platformVersion: "12.5.5"
platformVersion: "12.5.7"

- name: "iOS-11"
devices:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

## Unreleased

### Features

- feat: Core data operation in the main thread (#2879)

### Fixes

- Crash when serializing invalid objects (#2858)
- Possible crash in Core Data tracking (#2865)
- Don't send screenshots with either width or height of 0 (#2876))

## 8.4.0

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ GEM
nap (1.1.0)
naturally (2.2.1)
netrc (0.11.0)
nokogiri (1.14.2)
nokogiri (1.14.3)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
optparse (0.1.1)
Expand Down
4 changes: 0 additions & 4 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
0A2D8D9828997887008720F6 /* NSLocale+Sentry.h in Headers */ = {isa = PBXBuildFile; fileRef = 0A2D8D9728997887008720F6 /* NSLocale+Sentry.h */; };
0A2D8DA8289BC905008720F6 /* SentryViewHierarchy.h in Headers */ = {isa = PBXBuildFile; fileRef = 0A2D8DA6289BC905008720F6 /* SentryViewHierarchy.h */; };
0A2D8DA9289BC905008720F6 /* SentryViewHierarchy.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A2D8DA7289BC905008720F6 /* SentryViewHierarchy.m */; };
0A4EDEA928D3461B00FA67CB /* SentryPerformanceTracker+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 0A4EDEA828D3461B00FA67CB /* SentryPerformanceTracker+Private.h */; };
0A5370A128A3EC2400B2DCDE /* SentryViewHierarchyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A5370A028A3EC2400B2DCDE /* SentryViewHierarchyTests.swift */; };
0A56DA5F28ABA01B00C400D5 /* SentryTransactionContext+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 0A56DA5E28ABA01B00C400D5 /* SentryTransactionContext+Private.h */; };
0A6EEADD28A657970076B469 /* UIViewRecursiveDescriptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6EEADC28A657970076B469 /* UIViewRecursiveDescriptionTests.swift */; };
Expand Down Expand Up @@ -889,7 +888,6 @@
0A2D8D9728997887008720F6 /* NSLocale+Sentry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "NSLocale+Sentry.h"; path = "include/NSLocale+Sentry.h"; sourceTree = "<group>"; };
0A2D8DA6289BC905008720F6 /* SentryViewHierarchy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryViewHierarchy.h; path = include/SentryViewHierarchy.h; sourceTree = "<group>"; };
0A2D8DA7289BC905008720F6 /* SentryViewHierarchy.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryViewHierarchy.m; sourceTree = "<group>"; };
0A4EDEA828D3461B00FA67CB /* SentryPerformanceTracker+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryPerformanceTracker+Private.h"; path = "include/SentryPerformanceTracker+Private.h"; sourceTree = "<group>"; };
0A5370A028A3EC2400B2DCDE /* SentryViewHierarchyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryViewHierarchyTests.swift; sourceTree = "<group>"; };
0A56DA5E28ABA01B00C400D5 /* SentryTransactionContext+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryTransactionContext+Private.h"; path = "include/SentryTransactionContext+Private.h"; sourceTree = "<group>"; };
0A6EEADC28A657970076B469 /* UIViewRecursiveDescriptionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewRecursiveDescriptionTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2834,7 +2832,6 @@
8EAE9804261E87120073B6B3 /* SentryUIViewControllerPerformanceTracker.m */,
8EAE9809261E9F530073B6B3 /* SentryPerformanceTracker.h */,
8EBF870726140D37001A6853 /* SentryPerformanceTracker.m */,
0A4EDEA828D3461B00FA67CB /* SentryPerformanceTracker+Private.h */,
D8BFE37029A3782F002E73F3 /* SentryTimeToDisplayTracker.h */,
D8BFE37129A3782F002E73F3 /* SentryTimeToDisplayTracker.m */,
);
Expand Down Expand Up @@ -3380,7 +3377,6 @@
63AA76991EB9C1C200D153DE /* SentryDefines.h in Headers */,
D86B6835294348A400B8B1FC /* SentryAttachment+Private.h in Headers */,
84AF45A629A7FFA500FBB177 /* SentryTracerConcurrency.h in Headers */,
0A4EDEA928D3461B00FA67CB /* SentryPerformanceTracker+Private.h in Headers */,
7B2A70DB27D607CF008B0D15 /* SentryThreadWrapper.h in Headers */,
8EAE980B261E9F530073B6B3 /* SentryPerformanceTracker.h in Headers */,
63FE718520DA4C1100CDBAE8 /* SentryCrashC.h in Headers */,
Expand Down
2 changes: 1 addition & 1 deletion SentryTestUtils/TestSentryNSTimerWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TestSentryNSTimerWrapper: SentryNSTimerWrapper {
var block: ((Timer) -> Void)?
}

public lazy var overrides = Overrides()
public var overrides = Overrides()

public override func scheduledTimer(withTimeInterval interval: TimeInterval, repeats: Bool, block: @escaping (Timer) -> Void) -> Timer {
let timer = TestTimer()
Expand Down
11 changes: 9 additions & 2 deletions Sources/Sentry/SentryAppStartTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ - (instancetype)initWithCurrentDateProvider:(id<SentryCurrentDateProvider>)curre
self.wasInBackground = NO;
self.didFinishLaunchingTimestamp = [currentDateProvider date];
self.enablePreWarmedAppStartTracing = enablePreWarmedAppStartTracing;
self.isRunning = NO;
}
return self;
}
Expand Down Expand Up @@ -116,6 +117,8 @@ - (void)start
# if SENTRY_HAS_UIKIT
[self.appStateManager start];
# endif

self.isRunning = YES;
}

- (void)buildAppStartMeasurement
Expand Down Expand Up @@ -208,8 +211,8 @@ - (void)buildAppStartMeasurement
SentrySDK.appStartMeasurement = appStartMeasurement;
};

// With only running this once we know that the process is a new one when the following
// code is executed.
// With only running this once we know that the process is a new one when the following
// code is executed.
// We need to make sure the block runs on each test instead of only once
# if TEST
block();
Expand Down Expand Up @@ -285,6 +288,10 @@ - (void)stop
[NSNotificationCenter.defaultCenter removeObserver:self
name:UIApplicationDidEnterBackgroundNotification
object:nil];

# if TEST
self.isRunning = NO;
# endif
}

- (void)dealloc
Expand Down
13 changes: 2 additions & 11 deletions Sources/Sentry/SentryClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,9 @@ - (instancetype)initWithOptions:(SentryOptions *)options
transportAdapter:(SentryTransportAdapter *)transportAdapter

{
SentryInAppLogic *inAppLogic =
[[SentryInAppLogic alloc] initWithInAppIncludes:options.inAppIncludes
inAppExcludes:options.inAppExcludes];
SentryCrashStackEntryMapper *crashStackEntryMapper =
[[SentryCrashStackEntryMapper alloc] initWithInAppLogic:inAppLogic];
SentryStacktraceBuilder *stacktraceBuilder =
[[SentryStacktraceBuilder alloc] initWithCrashStackEntryMapper:crashStackEntryMapper];
id<SentryCrashMachineContextWrapper> machineContextWrapper =
[[SentryCrashDefaultMachineContextWrapper alloc] init];
SentryThreadInspector *threadInspector =
[[SentryThreadInspector alloc] initWithStacktraceBuilder:stacktraceBuilder
andMachineContextWrapper:machineContextWrapper];
[[SentryThreadInspector alloc] initWithOptions:options];

SentryExtraContextProvider *extraContextProvider = [SentryExtraContextProvider sharedInstance];

return [self initWithOptions:options
Expand Down
30 changes: 28 additions & 2 deletions Sources/Sentry/SentryCoreDataTracker.m
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@

#import "SentryCoreDataTracker.h"
#import "SentryFrame.h"
#import "SentryHub+Private.h"
#import "SentryInternalDefines.h"
#import "SentryLog.h"
#import "SentryNSProcessInfoWrapper.h"
#import "SentryPredicateDescriptor.h"
#import "SentrySDK+Private.h"
#import "SentryScope+Private.h"
#import "SentrySpanProtocol.h"
@import SentryPrivate;
#import "SentryStacktrace.h"
#import "SentryThreadInspector.h"

@implementation SentryCoreDataTracker {
SentryPredicateDescriptor *predicateDescriptor;
SentryThreadInspector *_threadInspector;
SentryNSProcessInfoWrapper *_processInfoWrapper;
}

- (instancetype)init
- (instancetype)initWithThreadInspector:(SentryThreadInspector *)threadInspector
processInfoWrapper:(SentryNSProcessInfoWrapper *)processInfoWrapper;
{
if (self = [super init]) {
predicateDescriptor = [[SentryPredicateDescriptor alloc] init];
_threadInspector = threadInspector;
_processInfoWrapper = processInfoWrapper;
}
return self;
}
Expand Down Expand Up @@ -48,8 +58,9 @@ - (NSArray *)managedObjectContext:(NSManagedObjectContext *)context
NSArray *result = original(request, error);

if (fetchSpan) {
[fetchSpan setDataValue:[NSNumber numberWithInteger:result.count] forKey:@"read_count"];
[self mainThreadExtraInfo:fetchSpan];

[fetchSpan setDataValue:[NSNumber numberWithInteger:result.count] forKey:@"read_count"];
[fetchSpan
finishWithStatus:result == nil ? kSentrySpanStatusInternalError : kSentrySpanStatusOk];

Expand Down Expand Up @@ -92,6 +103,7 @@ - (BOOL)managedObjectContext:(NSManagedObjectContext *)context
BOOL result = original(error);

if (fetchSpan) {
[self mainThreadExtraInfo:fetchSpan];
[fetchSpan finishWithStatus:result ? kSentrySpanStatusOk : kSentrySpanStatusInternalError];

SENTRY_LOG_DEBUG(@"SentryCoreDataTracker automatically finished span with status: %@",
Expand All @@ -101,6 +113,20 @@ - (BOOL)managedObjectContext:(NSManagedObjectContext *)context
return result;
}

- (void)mainThreadExtraInfo:(SentrySpan *)span
{
BOOL isMainThread = [NSThread isMainThread];

[span setDataValue:@(isMainThread) forKey:BLOCKED_MAIN_THREAD];

if (!isMainThread) {
return;
}

SentryStacktrace *stackTrace = [_threadInspector stacktraceForCurrentThreadAsyncUnsafe];
[span setFrames:stackTrace.frames];
}

- (NSString *)descriptionForOperations:
(NSDictionary<NSString *, NSDictionary<NSString *, NSNumber *> *> *)operations
inContext:(NSManagedObjectContext *)context
Expand Down
7 changes: 6 additions & 1 deletion Sources/Sentry/SentryCoreDataTrackingIntegration.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#import "SentryCoreDataTrackingIntegration.h"
#import "SentryCoreDataSwizzling.h"
#import "SentryCoreDataTracker.h"
#import "SentryDependencyContainer.h"
#import "SentryLog.h"
#import "SentryNSDataSwizzling.h"
#import "SentryNSProcessInfoWrapper.h"
#import "SentryOptions.h"
#import "SentryThreadInspector.h"

@interface
SentryCoreDataTrackingIntegration ()
Expand All @@ -20,7 +23,9 @@ - (BOOL)installWithOptions:(SentryOptions *)options
return NO;
}

self.tracker = [[SentryCoreDataTracker alloc] init];
self.tracker = [[SentryCoreDataTracker alloc]
initWithThreadInspector:[[SentryThreadInspector alloc] initWithOptions:options]
processInfoWrapper:[SentryDependencyContainer.sharedInstance processInfoWrapper]];
[SentryCoreDataSwizzling.sharedInstance startWithMiddleware:self.tracker];

return YES;
Expand Down
Loading

0 comments on commit 8e23a00

Please sign in to comment.