diff --git a/tracker/tracker/CHANGELOG.md b/tracker/tracker/CHANGELOG.md index d76b100ba..da9cb3173 100644 --- a/tracker/tracker/CHANGELOG.md +++ b/tracker/tracker/CHANGELOG.md @@ -1,3 +1,7 @@ +# 7.0.3 + +- Prevent auto restart after manual stop + # 7.0.2 - fixed header sanitization for axios causing empty string in some cases diff --git a/tracker/tracker/package.json b/tracker/tracker/package.json index bbd632374..93031dddf 100644 --- a/tracker/tracker/package.json +++ b/tracker/tracker/package.json @@ -1,7 +1,7 @@ { "name": "@openreplay/tracker", "description": "The OpenReplay tracker main package", - "version": "7.0.2", + "version": "7.0.3", "keywords": [ "logging", "replay" diff --git a/tracker/tracker/src/webworker/BatchWriter.ts b/tracker/tracker/src/webworker/BatchWriter.ts index cf7a6e4b4..bd1d42084 100644 --- a/tracker/tracker/src/webworker/BatchWriter.ts +++ b/tracker/tracker/src/webworker/BatchWriter.ts @@ -134,7 +134,8 @@ export default class BatchWriter { if (this.isEmpty) { return } - this.onBatch(this.encoder.flush()) + const batch = this.encoder.flush() + this.onBatch(batch) this.prepare() } diff --git a/tracker/tracker/src/webworker/QueueSender.ts b/tracker/tracker/src/webworker/QueueSender.ts index 5fedb48c0..f8cbaa43e 100644 --- a/tracker/tracker/src/webworker/QueueSender.ts +++ b/tracker/tracker/src/webworker/QueueSender.ts @@ -7,7 +7,9 @@ export default class QueueSender { private readonly queue: Array = [] private readonly ingestURL private token: string | null = null - private isCompressing = false + // its actually on #24 + // eslint-disable-next-line + private isCompressing constructor( ingestBaseURL: string, @@ -18,7 +20,11 @@ export default class QueueSender { private readonly onCompress?: (batch: Uint8Array) => any, ) { this.ingestURL = ingestBaseURL + INGEST_PATH - if (onCompress !== undefined) this.isCompressing = true + if (onCompress !== undefined) { + this.isCompressing = true + } else { + this.isCompressing = false + } } authorise(token: string): void { @@ -124,7 +130,11 @@ export default class QueueSender { } clean() { - this.queue.length = 0 - this.token = null + // sending last batch and closing the shop + this.sendNext() + setTimeout(() => { + this.token = null + this.queue.length = 0 + }, 100) } } diff --git a/tracker/tracker/src/webworker/index.ts b/tracker/tracker/src/webworker/index.ts index a1b836502..68a1e4467 100644 --- a/tracker/tracker/src/webworker/index.ts +++ b/tracker/tracker/src/webworker/index.ts @@ -2,7 +2,7 @@ // https://github.com/microsoft/TypeScript/issues/14877 // At the moment "webworker" lib conflicts with jest-environment-jsdom that uses "dom" lib import { Type as MType } from '../common/messages.gen.js' -import { ToWorkerData, FromWorkerData } from '../common/interaction.js' +import { FromWorkerData } from '../common/interaction.js' import QueueSender from './QueueSender.js' import BatchWriter from './BatchWriter.js' @@ -14,6 +14,7 @@ enum WorkerStatus { Starting, Stopping, Active, + Stopped, } const AUTO_SEND_INTERVAL = 10 * 1000 @@ -32,6 +33,7 @@ function finalize(): void { function resetWriter(): void { if (writer) { writer.clean() + // we don't need to wait for anything here since its sync writer = null } } @@ -39,7 +41,10 @@ function resetWriter(): void { function resetSender(): void { if (sender) { sender.clean() - sender = null + // allowing some time to send last batch + setTimeout(() => { + sender = null + }, 500) } } @@ -55,6 +60,7 @@ function reset(): void { } function initiateRestart(): void { + if (workerStatus === WorkerStatus.Stopped) return postMessage('restart') reset() } @@ -75,7 +81,7 @@ self.onmessage = ({ data }: any): any => { if (data === 'stop') { finalize() reset() - return + return (workerStatus = WorkerStatus.Stopped) } if (Array.isArray(data)) {