Skip to content

Fix upload speed inflation from HTTP errors + document server body size limit#820

Open
EmanuelPeixoto wants to merge 2 commits into
librespeed:masterfrom
EmanuelPeixoto:fix-upload-http-status
Open

Fix upload speed inflation from HTTP errors + document server body size limit#820
EmanuelPeixoto wants to merge 2 commits into
librespeed:masterfrom
EmanuelPeixoto:fix-upload-http-status

Conversation

@EmanuelPeixoto

@EmanuelPeixoto EmanuelPeixoto commented Jul 22, 2026

Copy link
Copy Markdown

What

  • speedtest_worker.js: xhr.upload.onload now checks HTTP status before restarting the upload stream. Non-2xx responses (e.g. HTTP 413 from undersized client_max_body_size) are
    treated as failures instead of inflating upload speed measurements.
  • doc.md: added explicit nginx/Apache/IIS config examples for client_max_body_size / LimitRequestBody to prevent HTTP 413 errors on 20 MB upload blobs.

Why

Server returning 413 (body too large) caused onload to fire instantly with the worker interpreting it as a successful upload, reporting impossible speeds (7-10 Gbps on gigabit LAN).
Fixes both the symptom (code) and the root cause (docs).

Closes #819

- speedtest_worker.js: xhr.upload.onload now checks xhr.status
  before restarting the upload stream. Non-2xx responses (e.g.
  HTTP 413 from undersized client_max_body_size) are treated as
  failures instead of inflating upload speed measurements.

- doc.md: added explicit nginx/Apache/IIS configuration examples
  for client_max_body_size / LimitRequestBody to prevent HTTP 413
  errors on the 20MB upload test blobs.

@sstidl sstidl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review

Changes requested — the HTTP-status check is attached to the wrong XHR lifecycle event.

xhr.upload.onload fires when the request body has been uploaded, which does not guarantee that response headers (and therefore xhr.status) are available. Valid requests can still have status 0 at that point and will be treated as failures/restarted.

Please perform the status check and stream restart from xhr.onload instead. Keep xhr.upload.onprogress for byte accounting, and handle transport failures with xhr.onerror.

Also, the documentation currently mentions IIS but does not include the promised web.config example or clarify that maxAllowedContentLength is expressed in bytes.

Comment thread speedtest_worker.js
totLoaded += loadDiff;
prevLoaded = event.loaded;
}.bind(this);
xhr[i].upload.onload = function() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upload.onload marks completion of sending the request body, not completion of the HTTP transaction. The server response/status may not be available yet, so xhr.status can be 0 even for a successful upload. Put this status-dependent logic in xhr.onload (and use xhr.onerror for network errors) so a completed response is what determines whether to restart or fail the stream.

- speedtest_worker.js: moved HTTP status check from xhr.upload.onload
  (body sent, response may not be available) to xhr.onload
  (full HTTP transaction complete, xhr.status is reliable).
- doc.md: added full IIS web.config example with maxAllowedContentLength.
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.

Upload speed inflated on low-latency connections (v6.1.0)

2 participants