Skip to content

Fix xhr responsetext crash#2521

Closed
victoritis wants to merge 542 commits intofilesender:developmentfrom
victoritis:fix-xhr-responsetext-crash
Closed

Fix xhr responsetext crash#2521
victoritis wants to merge 542 commits intofilesender:developmentfrom
victoritis:fix-xhr-responsetext-crash

Conversation

@victoritis
Copy link
Copy Markdown

Description

This PR fixes a JavaScript crash that occurs during large file uploads, particularly in Firefox when network instability (HTTP/3/QUIC resets) causes XHR responses to be empty or undefined.

The Problem

When uploading large files, FileSender uses Terasender workers to upload chunks in parallel. If a network error occurs (timeout, connection reset, HTTP/3 instability), the XHR responseText property may be undefined instead of a string.

The current code attempts to call .replace() directly on responseText:

var msg = xhr.responseText.replace(/^\s+/, '').replace(/\s+$/, '');

This causes a TypeError: Cannot read property 'replace' of undefined, which:

  • Crashes the JavaScript execution
  • Prevents the built-in retry mechanism from activating
  • Results in a blank error screen for users

Affected files:

  • www/js/client.js (line 227) - General API error handling
  • www/js/terasender/terasender_worker.js (line 508) - Chunk upload error handling

The Solution

Added defensive null-checking before accessing responseText:

var msg = (xhr.responseText || '').replace(/^\s+/, '').replace(/\s+$/, '');

This ensures:

  • If responseText exists → Works exactly as before
  • If responseText is undefined/null → Uses empty string, preventing crash
  • The existing retry mechanism can now activate properly

Impact

  • Before fix: Network errors during upload → JS crash → Upload fails permanently
  • After fix: Network errors during upload → Graceful handling → Retry mechanism activates

Files Modified

  • www/js/client.js (line 227)
  • www/js/terasender/terasender_worker.js (line 508)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Enhancement

How Has This Been Tested?

Tested in production environment with Firefox where HTTP/3 network resets were causing upload failures on large files (500MB+). After applying the fix, uploads complete successfully with automatic retries when network hiccups occur.

madsi1m and others added 30 commits February 11, 2025 09:15
* remove debug "hi there"

* remove total from data_per_day_graph as it is on the graph next to it

* Add/Use transferssizeidpview

* add loading balls to statistics_page

* add missing h3

* clean up graph divs

* more UX stuff for tables
* remove debug "hi there"

* fix SQL joins for idp linking

* add browserstatsview, to speed up browserstats table for admins

* fix idp join for stats page query in template

* prefer DBLayer::timeStampToEpoch() over UNIX_TIMESTAMP()

* nicer js loading animation/padding
* a few typeOs

* PHP Notice:  Only variables should be passed by reference
* first go at adding idp in path

* rework storage_filesystem_per_idp
…ilesender#2120)

New option to allow the path from storage to be stored per file in the
database. This is the first step towards allowing various settings
like per day buckets and idp in the storage path to be changed and
existing files continue to be downloadable.

This PR only optionally stores the path. A future PR will allow that
information to be used and this allow storage settings to change and
existing files (uploaded with this new
storage_filesystem_explicitly_store_subpath_per_file enabled) to
continue to be downloaded in the face of settings changes.
also move to the dbobject api to keep it simple.
* fix typeO

* make filesbywhoview a left join

* more views that should be LEFT JOINs

* typeOs

* fix mime_type query as it was mixing user/auth ids
* Revert default changes where there is no clear benefit
* fix typeO

* fix Joins on recipientsidpview
* fix typeO

* add transfersfilesidpview
* fix typeO

* g for Guests makes more sense than t

* remove d2/d5 as not needed and use existing views where possible
* fix typeO in sql in statistics_transfers_speeds_graph.php
- Filter duplicate languages
- Only show if there are multiple languages configured
monkeyiq and others added 29 commits December 21, 2025 04:02
…e-update

d3: update the icon names after the fa version bump
…ports-2025-12-25-1766606266

i18n: ui3: auto import from poedtor on 2025-12-25-1766606266
…n-string-update-for-release-3.1

bump in build version number
use the new randomuid name for this call too
…-string-update-for-release-3.2

bump in build version number
seems f['size'] is now a string? Let's cast it as an int in python
…-string-update-for-release-3.3

bump in build version number
Add `selectable_transfer_days_valid` and `selectable_guest_days_valid` to the
config file, allowing administrators to define custom expiry date options in the
Upload and Guest forms.
…b-info-copy-out

2026/jan/docs mariadb info copy out
…tail-pass-token

read and send token if it is valid
This seems to have been left out with the efficiency updates.
@victoritis victoritis closed this Jan 21, 2026
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.

8 participants