fix: Avoid mutating live network requests - #8650
Merged
Merged
Conversation
Copy the task's current request before adding trace propagation headers so CFNetwork never observes concurrent in-place mutations. Fixes #8519
philprime
force-pushed
the
philprime/network-instrumentation-8519
branch
from
August 3, 2026 09:53
00b2ec6 to
005ad55
Compare
philprime
changed the base branch from
philprime/network-tracker-conversion
to
main
August 3, 2026 09:53
philprime
marked this pull request as ready for review
August 3, 2026 09:55
philprime
requested review from
NinjaLikesCheez,
itaybre,
noahsmartin and
philipphofmann
as code owners
August 3, 2026 09:55
📲 Install BuildsiOS
|
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| dcb456a | 1220.98 ms | 1246.74 ms | 25.76 ms |
| 952f116 | 1221.55 ms | 1248.72 ms | 27.17 ms |
| 706c4c0 | 1213.06 ms | 1252.94 ms | 39.88 ms |
| b6b0d1d | 1236.69 ms | 1270.22 ms | 33.52 ms |
| 8693a8f | 1222.37 ms | 1249.31 ms | 26.95 ms |
| 52f26a1 | 1227.29 ms | 1261.50 ms | 34.21 ms |
| b6fa517 | 1218.83 ms | 1257.47 ms | 38.63 ms |
| 7f28cd4 | 1215.77 ms | 1242.98 ms | 27.21 ms |
| 5df460d | 1230.49 ms | 1260.69 ms | 30.20 ms |
| f2e9a12 | 1223.86 ms | 1264.56 ms | 40.70 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| dcb456a | 24.14 KiB | 1.22 MiB | 1.20 MiB |
| 952f116 | 24.14 KiB | 1.24 MiB | 1.21 MiB |
| 706c4c0 | 24.14 KiB | 1.26 MiB | 1.23 MiB |
| b6b0d1d | 24.14 KiB | 1.18 MiB | 1.16 MiB |
| 8693a8f | 24.14 KiB | 1.16 MiB | 1.13 MiB |
| 52f26a1 | 24.14 KiB | 1.19 MiB | 1.17 MiB |
| b6fa517 | 24.14 KiB | 1.14 MiB | 1.12 MiB |
| 7f28cd4 | 24.14 KiB | 1.23 MiB | 1.21 MiB |
| 5df460d | 24.14 KiB | 1.22 MiB | 1.20 MiB |
| f2e9a12 | 24.14 KiB | 1.27 MiB | 1.25 MiB |
Previous results on branch: philprime/network-instrumentation-8519
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 7d22285 | 1211.29 ms | 1255.36 ms | 44.06 ms |
| 65f5b6f | 1206.22 ms | 1244.58 ms | 38.36 ms |
| be2121d | 1233.62 ms | 1265.92 ms | 32.29 ms |
| dca42ff | 1205.02 ms | 1254.36 ms | 49.34 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 7d22285 | 24.14 KiB | 1.26 MiB | 1.23 MiB |
| 65f5b6f | 24.14 KiB | 1.27 MiB | 1.25 MiB |
| be2121d | 24.14 KiB | 1.27 MiB | 1.25 MiB |
| dca42ff | 24.14 KiB | 1.26 MiB | 1.23 MiB |
philprime
marked this pull request as draft
August 3, 2026 10:47
Model setCurrentRequest: on the download and upload task mocks to match real NSURLSession task behavior, and add tests asserting trace headers are applied for both task types. Refs #8519
…trumentation-8519 # Conflicts: # Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerIntegrationTestServerTests.swift
philprime
marked this pull request as ready for review
August 5, 2026 12:44
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a7cde10. Configure here.
…trumentation-8519
philprime
enabled auto-merge (squash)
August 6, 2026 12:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

📜 Description
Copy
URLSessionTask.currentRequestbefore adding trace propagation headers and install the copied request throughsetCurrentRequest:. This prevents Sentry from mutating a request that CFNetwork may be reading concurrently.Add regression coverage that verifies a mutable current request remains unchanged while the replacement request receives the trace headers.
💡 Motivation and Context
Network instrumentation previously mutated mutable
currentRequestinstances in place. Repeated or concurrent task resumes could race CFNetwork's access to the same request header storage and crash in CoreFoundation or CFNetwork.The Swift network tracker conversion does not remove this path because header injection still delegates to
SentryTracePropagation.Fixes #8519
💚 How did you test it?
make formatmake analyzemake build-ios FOR_AGENTS=truemake build-macos FOR_AGENTS=truemake test-ios FOR_AGENTS=true ONLY_TESTING=SentryTests/SentryTracePropagationTests,SentryTests/SentryNetworkTrackerTestsThe focused iOS run executed 100 tests with 0 failures. The equivalent macOS test command is currently blocked by unrelated test-target compilation errors in
SentryOptionsDictionaryTests,SentrySpotlightTransportTests, andSentryTransportFactoryTestson the base branch.📝 Checklist
You have to check all boxes before merging:
sendDefaultPIIis enabled.