Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 11, 2026

Workers were never terminated after test completion, causing orphaned workers to continue making requests. This resulted in resource contention and corrupted measurements when running multiple tests sequentially—particularly manifesting as abnormally high jitter values (4000+ ms instead of <10 ms).

Changes

  • Worker termination on test start: Terminate any existing worker before creating new one
  • Worker termination on completion: Clean up worker when test reaches final state (4=finished, 5=aborted)
  • Abort safety mechanism: Add 1s timeout to force cleanup if worker doesn't respond to abort message
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());
  // ...
}

Validation

Created examples/test_multiple_instances.html demonstrating multiple sequential tests now produce consistent measurements:

Before:
issue-screenshot

After:
fixed-screenshot

Original prompt

This section details on the original issue you should resolve

<issue_title>The second test doesn't work.</issue_title>
<issue_description>I have two Speedtest()'s on the same page. The second test sometimes behaves strangely.

Image

Are there global variables in speedtest_worker.js, maybe?

My server has two network cards, having two IP addresses. I set two backends, two virtual hosts, which actually serve the same files but from different IP addresses. I modified slightly speedtest.js (the released version) in order to have a single backend, one in each Speedtest() instance.

My server has two network cards, with two IP addresses. I've set up two backends, two virtual hosts, which actually serve the same files but from different IP addresses. I've slightly modified speedtest.js (the released version) to have a single backend, one for each Speedtest() instance. The first run on after reloading the page runs just fine. The second run often falters, irrespective of which backend is started first.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits January 11, 2026 22:26
Co-authored-by: sstidl <12804296+sstidl@users.noreply.github.com>
Co-authored-by: sstidl <12804296+sstidl@users.noreply.github.com>
Co-authored-by: sstidl <12804296+sstidl@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with second Speedtest not working Fix worker lifecycle: terminate workers to prevent interference between tests Jan 11, 2026
@alevesely
Copy link

The change looks clever and I applied it to my speedtest.js. However, the second test still shows anomalous results: download about a half and upload at 0.00. Sometimes there's high jitter, sometimes not.

@sstidl
Copy link
Collaborator

sstidl commented Jan 12, 2026

The change looks clever and I applied it to my speedtest.js. However, the second test still shows anomalous results: download about a half and upload at 0.00. Sometimes there's high jitter, sometimes not.

Is your testing in parallel or sequentially?
If in parallel maybe this is too much for the browser

@alevesely
Copy link

We're testing sequentially. The second test cannot start before the first is done.

I primarily run tests on the local network, which is connected to a third interface, the default gateway for the local network. Some instabilities appear to be related to the server's internal forwarding. However, the previously reported anomaly—half the download rate and zero upload rate—occurs in the second test, regardless of which interface was tested first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The second test doesn't work.

3 participants