question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Put request on Edge and Firefox triggers 'Network error'

See original GitHub issue

Describe the bug On Edge and Firefox I want to upload a file to google cloud. When I follow their instructions in order to put the file by chunks, it works fine on chrome latest version, but fails silently on Edge and Firefox.

On Edge the following happens :

  • We prepare a PUT request with the correct headers Content-Type and Content-Range
  • The request is send with the first chunk of bytes as payload
  • When the request should be valid and we then proceed to the next chunk of data, the request silently errored (no catch triggered)
  • Because we use axios-retry, the request is send again, still failing silently.

On Firefox the following happens :

  • We prepare a PUT request with the correct headers Content-Type and Content-Range
  • The request is send with the first chunk of bytes as payload
  • When the request should be valid and we then proceed to the next chunk of data, the request silently errored (no catch triggered) and we have to wait for the gcloud timeout (5min)
  • Because we use axios-retry, the request is send again, still failing silently.

To Reproduce

import baseAxios from 'axios';
import axiosRetry from 'axios-retry';
import reader from '@/libs/FileReader';

const axios = baseAxios.create();
axiosRetry(axios, {
    retries: 5,
    retryDelay: (retryCount = 0) => (
        (2 ** retryCount) * 1000
    ),
});

function hex2bin(hex: string) {
    const bytes = [];

    for (let x = 0; x < (hex.length - 1); x += 2) {
        bytes.push(parseInt(hex.substring(x, x + 2), 16));
    }

    return String.fromCharCode(...bytes);
}

function uploadChunk(file: File, chunkSize: number, index: number, uploadUrl: string) {
    const start = index * chunkSize;
    const end = Math.min(start + chunkSize, file.size);
    const blob = file.slice(start, end);

    const headers = {
        'Content-Type': file.type,
        'Content-Range': `bytes ${start}-${end - 1}/${file.size}`,
    };

    const validateStatus = (status: number) => (
        [200, 201, 308].indexOf(status) > -1
    );

    return reader.readChunk(blob).then((chunk: string | ArrayBuffer) => {
        try {
            return axios.put(uploadUrl, chunk, {
                headers,
                validateStatus,
            }).then(() => {
                // Works fine on Chrome and IE11 but not Edge and Firefox
                console.log('RES');
                return;
            }).catch((e) => {
                // Nothing printed here on Firefox and Edge
                console.info('ERR: ', e);
            });
        } catch (e) {
            // Nothing printed here on Firefox and Edge
            console.log('CATCH: ', e);
        }
    });
}

export async function upload(
    file: File,
    hash: string,
    signedUrl: string,
    onProgress: (percentage: number) => void,
) {
    // min 256KB, max 2MB
    const chunkSize = (file.size < 2097152) ? 262144 : 2097152;
    const chunks = Math.ceil(file.size / chunkSize);

    const headers = {
        'Content-Type': file.type,
        'Content-MD5': btoa(hex2bin(hash)),
        'x-goog-resumable': 'start',
    };

    const result = await axios.post(signedUrl, null, { headers }); // Works fine
    const uploadUrl = result.headers.location;

    return initChunkUpload(chunks, chunkSize, onProgress, file, uploadUrl);
}

function initChunkUpload(
    chunks: number,
    chunkSize: number,
    onProgress: (percentage: number) => void,
    file: File,
    uploadUrl: string,
) {
    let currentChunk = 0;

    return new Promise((resolve, reject) => {
        const next = () => {
            uploadChunk(file, chunkSize, currentChunk, uploadUrl)
                .then(() => {
                    currentChunk += 1;
                    onProgress(Math.floor((currentChunk / chunks) * 100));

                    if (currentChunk < chunks) {
                        return next();
                    }
                    return resolve();
                })
                .catch(reject);
        };
        next();
    });
}

Expected behavior The PUT request should at least not fail silently and I should be able to send chunks of my file to google cloud.

Environment:

  • Axios Version: 0.19.0
  • OS: MacOS Mojave 10.14.6 (18G103) & Windows 10 Family 18362.356
  • Browser: Edge 44.18362.329.0 & Firefox 70.0 (64 bit)
  • Additional Library Versions: vue 2.6.10 & webpack 4.28.4 & axios-retry 3.1.2

Additional context/Screenshots

Observations

  • While debugging, I have found that the request might success depending on the media. I believe the weight of the data chunk to influence the behavior, making the bug a bit random.
  • On Firefox, the silent error is cath in the xhr.js here
  • On Edge and Firefox, when replacing axios put method by a fetch, it does work:
return fetch(uploadUrl,
       {
            method: 'PUT',
            headers,
            body: chunk,
        }).then(() => {
            // Works on Edge and FF
            console.log('RES');
            return;
        }).catch((e) => {
            console.info('ERR: ', e);
        });

EDGE screenshot

image (1)

Firefox screenshot

Screenshot 2019-10-23 at 15 20 02

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jasonsaaymancommented, May 16, 2021

Closing in favour of #2103

0reactions
nayanbhanacommented, Jul 10, 2020

I have this issue right now on Microsoft Edge, no clue how to fix it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firefox can't load websites but other browsers can
This article describes problems where Firefox cannot load websites but other Web browsers (such as Microsoft Edge or Internet ExplorerSafariEpiphany on ...
Read more >
Websites don't load - troubleshoot and fix error messages
First, let's figure out where the problem is · Open a new tab and check to see if you can load another website...
Read more >
Server Not Found - Troubleshoot connection problems
If you can't connect to a website, you may see the Server Not Found error message. Learn how to troubleshoot and fix this...
Read more >
Firefox and other browsers can't load websites - Mozilla Support
If no web browsers on your computer can load websites, it indicates a problem with your Internet connection. The article describes some troubleshooting ......
Read more >
Network request list — Firefox Source Docs documentation
By default, the Network Monitor shows a list of all the network requests made in the ... (Starting in Firefox 80) On the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found