From ea90d77a3eff819089b95b507d5632344071c4c5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 11 Jan 2026 22:26:51 +0000 Subject: [PATCH] Fix worker not being terminated, causing interference between test runs Co-authored-by: sstidl <12804296+sstidl@users.noreply.github.com> --- speedtest.js | 10 +++ test_multiple_instances.html | 166 +++++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 test_multiple_instances.html diff --git a/speedtest.js b/speedtest.js index b2feca9..d664104 100755 --- a/speedtest.js +++ b/speedtest.js @@ -319,6 +319,11 @@ Speedtest.prototype = { */ start: function() { if (this._state == 3) throw "Test already running"; + // Terminate any existing worker from previous test + if (this.worker) { + this.worker.terminate(); + this.worker = null; + } this.worker = new Worker("speedtest_worker.js?r=" + Math.random()); this.worker.onmessage = function(e) { if (e.data === this._prevData) return; @@ -337,6 +342,11 @@ Speedtest.prototype = { } catch (e) { console.error("Speedtest onend event threw exception: " + e); } + // Terminate worker after test completes + if (this.worker) { + this.worker.terminate(); + this.worker = null; + } } }.bind(this); this.updater = setInterval( diff --git a/test_multiple_instances.html b/test_multiple_instances.html new file mode 100644 index 0000000..4254b27 --- /dev/null +++ b/test_multiple_instances.html @@ -0,0 +1,166 @@ + + + +
+This page tests running multiple Speedtest instances sequentially and simultaneously.
+ +