Skip to content

Commit

Permalink
impr: Stop canceling timer for manual transactions (#4380)
Browse files Browse the repository at this point in the history
Avoid canceling the deadline timer on the main thread when there is no
deadline timer when finishing a transaction.
  • Loading branch information
philipphofmann authored Sep 30, 2024
1 parent f3c0746 commit a3ce1a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- Speed up HTTP tracking for multiple requests in parallel (#4366)
- Slightly speed up SentryInAppLogic (#4370)
- Stop canceling timer for manual transactions (#4380)

## 8.37.0-beta.1

Expand Down
4 changes: 4 additions & 0 deletions Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ - (void)deadlineTimerFired

- (void)cancelDeadlineTimer
{
if (self.deadlineTimer == nil) {
return;
}

// If the main thread is busy the tracer could be deallocated in between.
__weak SentryTracer *weakSelf = self;

Expand Down
12 changes: 12 additions & 0 deletions Tests/SentryTests/Transaction/SentryTracerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,18 @@ class SentryTracerTests: XCTestCase {

fixture.timerFactory.fire()
}

func testDeadlineTimerForManualTransaction_NoWorkQueuedOnMainQueue() {
let sut = fixture.getSut(waitForChildren: false, idleTimeout: 0.0)

let invocationsBeforeFinish = fixture.dispatchQueue.blockOnMainInvocations.count

sut.finish()

let invocationsAfterFinish = fixture.dispatchQueue.blockOnMainInvocations.count

XCTAssertEqual(invocationsBeforeFinish, invocationsAfterFinish)
}

func testFramesofSpans_SetsDebugMeta() {
let sut = fixture.getSut()
Expand Down

0 comments on commit a3ce1a9

Please sign in to comment.