Skip to content

Commit 734d507

Browse files
authored
fix: dont call through to NSLog from profiler sampling thread (#3390)
Let's just avoid calling through to NSLog from the profiler's sampling thread until we can get a different logging solution in place, if we decide we need these logs at some point in the future.
1 parent 11b2ffa commit 734d507

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Crash when logging from certain profiling contexts (#3390)
8+
39
## 8.15.1
410

511
### Fixes

Sources/Sentry/SentryProfilingLogging.mm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "SentryProfilingLogging.hpp"
22

3-
#import "SentryLog.h"
3+
#if !defined(DEBUG)
4+
5+
# import "SentryLog.h"
46

57
namespace sentry {
68
namespace profiling {
@@ -41,3 +43,5 @@
4143

4244
} // namespace profiling
4345
} // namespace sentry
46+
47+
#endif // !defined(DEBUG)

Sources/Sentry/include/SentryProfilingLogging.hpp

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#pragma once
22

3-
#include <cerrno>
4-
#include <cstring>
5-
#include <string>
6-
#include <unistd.h>
7-
#include <vector>
3+
#if !defined(DEBUG)
4+
5+
# include <cerrno>
6+
# include <cstring>
7+
# include <string>
8+
# include <unistd.h>
9+
# include <vector>
810

911
namespace sentry {
1012
namespace profiling {
@@ -19,12 +21,25 @@ namespace profiling {
1921
} // namespace profiling
2022
} // namespace sentry
2123

22-
#define SENTRY_PROF_LOG_DEBUG(...) \
23-
sentry::profiling::log(sentry::profiling::LogLevel::Debug, __VA_ARGS__)
24-
#define SENTRY_PROF_LOG_WARN(...) \
25-
sentry::profiling::log(sentry::profiling::LogLevel::Warning, __VA_ARGS__)
26-
#define SENTRY_PROF_LOG_ERROR(...) \
27-
sentry::profiling::log(sentry::profiling::LogLevel::Error, __VA_ARGS__)
24+
# define SENTRY_PROF_LOG_DEBUG(...) \
25+
sentry::profiling::log(sentry::profiling::LogLevel::Debug, __VA_ARGS__)
26+
# define SENTRY_PROF_LOG_WARN(...) \
27+
sentry::profiling::log(sentry::profiling::LogLevel::Warning, __VA_ARGS__)
28+
# define SENTRY_PROF_LOG_ERROR(...) \
29+
sentry::profiling::log(sentry::profiling::LogLevel::Error, __VA_ARGS__)
30+
31+
#else
32+
33+
// Don't do anything with these in production until we can get a logging solution in place that
34+
// doesn't use NSLog. We can't use NSLog in these codepaths because it takes a lock, and if the
35+
// profiler's sampling thread is terminated before it can release that lock, then subsequent
36+
// attempts to acquire it can cause a crash.
37+
// See https://github.com/getsentry/sentry-cocoa/issues/3336#issuecomment-1802892052 for more info.
38+
# define SENTRY_PROF_LOG_DEBUG(...)
39+
# define SENTRY_PROF_LOG_WARN(...)
40+
# define SENTRY_PROF_LOG_ERROR(...)
41+
42+
#endif // !defined(DEBUG)
2843

2944
/**
3045
* Logs the error code returned by executing `statement`, and returns the

0 commit comments

Comments
 (0)