Skip to content

Commit 4afae53

Browse files
authored
fix: profiling memory growth fix (#3145)
- always ensure the profiler's timeout timer is scheduled on the main thread - keep references to any aborted profiler until its associated transaction is finished - fix testConcurrentSpansWithTimeout to properly regression test the scenario
1 parent 4af7581 commit 4afae53

19 files changed

+359
-210
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
- Renamed `enableTimeToFullDisplay` to `enableTimeToFullDisplayTracing` (#3106)
1313
- This is an experimental feature and may change at any time without a major revision.
14+
15+
### Fixes
16+
17+
- Fix potential unbounded memory growth when starting profiled transactions from non-main contexts (#3135)
1418

1519
## 8.9.0-beta.1
1620

Sentry.xcodeproj/project.pbxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3112,7 +3112,6 @@
31123112
8454CF8B293EAF9A006AC140 /* SentryMetricProfiler.mm */,
31133113
03F84D1127DD414C008FE43F /* SentryProfiler.h */,
31143114
03F84D2B27DD4191008FE43F /* SentryProfiler.mm */,
3115-
84A888FC28D9B11700C51DFD /* SentryProfiler+Test.h */,
31163115
84A888FC28D9B11700C51DFD /* SentryProfiler+Private.h */,
31173116
0354A22A2A134D9C003C3A04 /* SentryProfilerState.h */,
31183117
84281C642A57D36100EE88F2 /* SentryProfilerState+ObjCpp.h */,

SentryTestUtils/ClearTestState.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TestCleanup: NSObject {
4242
SentryTracer.resetAppStartMeasurementRead()
4343

4444
#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
45+
SentryProfiler.getCurrent().stop(for: .normal)
4546
SentryTracer.resetConcurrencyTracking()
4647
#endif
4748
}

SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#import "SentryNSTimerFactory.h"
2222
#import "SentryNetworkTracker.h"
2323
#import "SentryPerformanceTracker+Testing.h"
24+
#import "SentryProfiler+Test.h"
2425
#import "SentryRandom.h"
2526
#import "SentrySDK+Private.h"
2627
#import "SentrySDK+Tests.h"

Sources/Sentry/SentryFramesTracker.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ - (void)displayLinkCallback
123123
}
124124

125125
# if SENTRY_TARGET_PROFILING_SUPPORTED
126-
if ([SentryProfiler isRunning]) {
126+
if ([SentryProfiler isCurrentlyProfiling]) {
127127
BOOL hasNoFrameRatesYet = self.frameRateTimestamps.count == 0;
128128
uint64_t previousFrameRate
129129
= self.frameRateTimestamps.lastObject[@"value"].unsignedLongLongValue;
@@ -179,7 +179,7 @@ - (void)reportNewFrame
179179
# if SENTRY_TARGET_PROFILING_SUPPORTED
180180
- (void)recordTimestamp:(uint64_t)timestamp value:(NSNumber *)value array:(NSMutableArray *)array
181181
{
182-
BOOL shouldRecord = [SentryProfiler isRunning];
182+
BOOL shouldRecord = [SentryProfiler isCurrentlyProfiling];
183183
# if defined(TEST) || defined(TESTCI)
184184
shouldRecord = YES;
185185
# endif

Sources/Sentry/SentryNSNotificationCenterWrapper.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ + (NSNotificationName)willTerminateNotificationName
4646
- (void)addObserver:(id)observer
4747
selector:(SEL)aSelector
4848
name:(NSNotificationName)aName
49-
object:(id)anObject
49+
object:(nullable id)anObject
5050
{
5151
[NSNotificationCenter.defaultCenter addObserver:observer
5252
selector:aSelector
@@ -67,7 +67,7 @@ - (void)removeObserver:(id)observer name:(NSNotificationName)aName
6767
[NSNotificationCenter.defaultCenter removeObserver:observer name:aName object:nil];
6868
}
6969

70-
- (void)removeObserver:(id)observer name:(NSNotificationName)aName object:(id)anObject
70+
- (void)removeObserver:(id)observer name:(NSNotificationName)aName object:(nullable id)anObject
7171
{
7272
[NSNotificationCenter.defaultCenter removeObserver:observer name:aName object:anObject];
7373
}
@@ -77,7 +77,7 @@ - (void)removeObserver:(id)observer
7777
[NSNotificationCenter.defaultCenter removeObserver:observer];
7878
}
7979

80-
- (void)postNotificationName:(NSNotificationName)aName object:(id)anObject
80+
- (void)postNotificationName:(NSNotificationName)aName object:(nullable id)anObject
8181
{
8282
[NSNotificationCenter.defaultCenter postNotificationName:aName object:anObject];
8383
}

0 commit comments

Comments
 (0)