Skip to content

Remove app launch profiling error for sandboxed execution #7281

@philprime

Description

@philprime

Description

Description

When executing a binary linked to the Sentry SDK in a sandbox environment, which is common for Homebrew code completion evaluation, our app launch profiling logs an error message when trying to create the sentry.io directory in the default cache directory.

[Sentry] [error] [1769418490.135415] [SentryFileManager:848] Can't create base path to store launch profile config file: Error Domain=SentryErrorDomain Code=108 "Failed to create the directory at path /Users/philip/Library/Caches/tart/io.sentry." UserInfo={NSLocalizedDescription=Failed to create the directory at path /Users/philip/Library/Caches/tart/io.sentry., NSUnderlyingError=0x104e8b970 {Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “io.sentry” in the folder “tart”." UserInfo={NSFilePath=/Users/philip/Library/Caches/tart/io.sentry, NSURL=file:///Users/philip/Library/Caches/tart/io.sentry, NSUnderlyingError=0x104e8b940 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}}}
[Sentry] [error] [1769418490.135479] [SentryFileManager:895] Failed to construct the URL to check for launch profile configs.
Hello, World!

To reproduce the issue create a new SPM project with this Package.swift:

// swift-tools-version:5.10

import PackageDescription
let package = Package(
  name: "Tart",
  platforms: [
    .macOS(.v13)
  ],
  products: [
    .executable(name: "tart", targets: ["tart"])
  ],
  dependencies: [
    .package(url: "https://github.com/grpc/grpc-swift.git", .upToNextMajor(from: "1.24.2")),
    .package(url: "https://github.com/getsentry/sentry-cocoa", from: "8.51.1"),
  ],
  targets: [
    .executableTarget(name: "tart", dependencies: [
      .product(name: "GRPC", package: "grpc-swift"),
      .product(name: "Sentry", package: "sentry-cocoa"),
    ])
  ]
)

Create a single file at Sources/tart/Root.swift:

print("Hello, World!")

To create a sandboxed environment create a sandbox.sb:

(version 1)
(allow default)
(deny file* (subpath "/Users"))

And to execute it using make clean and make, create this Makefile:

all:
	swift build
	sandbox-exec -f sandbox.sb -- .build/arm64-apple-macosx/debug/tart

clean:
	rm -rf .build

During initial investigation I was only able to reproduce the error if the dependency https://github.com/grpc/grpc-swift.git was present too. When having sentry-cocoa as the only dependency the error message was not shown, maybe due to the absence of the Objective-C runtime triggering the + (void) load; method, starting app launch profiling.

Furthermore, this reproduce does not even contain a SentrySDK.configure block, meaning that setting the error log level will not work.

Other

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions