Skip to content

Commit 1d34b12

Browse files
committed
changed(tracing): always clear timeout when new activity starts within idle timeout
1 parent 4edac41 commit 1d34b12

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/tracing/src/idletransaction.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ export class IdleTransaction extends Transaction {
221221
// Remember timestampWithMs is in seconds, timeout is in ms
222222
const end = timestampWithMs() + timeout / 1000;
223223

224-
setTimeout(() => {
224+
if (this._initTimeout) {
225+
clearTimeout(this._initTimeout);
226+
}
227+
this._initTimeout = setTimeout(() => {
225228
if (!this._finished) {
226229
this.setTag(FINISH_REASON_TAG, IDLE_TRANSACTION_FINISH_REASONS[1]);
227230
this.finish(end);

packages/tracing/test/idletransaction.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ describe('IdleTransaction', () => {
188188
it('does not finish if a activity is started', () => {
189189
const transaction = new IdleTransaction({ name: 'foo', startTimestamp: 1234 }, hub, DEFAULT_IDLE_TIMEOUT);
190190
transaction.initSpanRecorder(10);
191+
const span = transaction.startChild({});
192+
span.finish();
191193
transaction.startChild({});
192194

193195
jest.advanceTimersByTime(DEFAULT_IDLE_TIMEOUT);

0 commit comments

Comments
 (0)