Skip to content

Commit

Permalink
Attempts to fix a small race condition in setting that.results.c2sRate.
Browse files Browse the repository at this point in the history
  • Loading branch information
nkinkade committed Apr 10, 2020
1 parent bcb0448 commit 313620c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion html/ndt-browser-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ NDTjs.prototype.ndtC2sTest = function () {
testConnection.send(dataToSend);
totalSent += dataToSend.length;
}
if (that.updateInterval && currentTime > (testStart + nextCallback)) {
// Subtracting 0.1s from currentTime below ensures that this expression
// will always evaluate to false just a tiny bit before 10s, which
// eliminates a race condition between setting that.results.c2sRate
// here and further down in this code.
if (that.updateInterval && (currentTime - 0.1) > (testStart + nextCallback)) {
that.results.c2sRate = 8 * (totalSent - testConnection.bufferedAmount)
/ 1000 / (currentTime - testStart);
that.callbacks.onprogress('interval_c2s', that.results);
Expand Down

0 comments on commit 313620c

Please sign in to comment.