Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial request body when using Queue #1733

Closed
cacciatc opened this issue Oct 25, 2018 · 4 comments
Closed

Partial request body when using Queue #1733

cacciatc opened this issue Oct 25, 2018 · 4 comments

Comments

@cacciatc
Copy link

Library Affected:
Queue 3.6.2

Browser & Platform:
Google Chrome 70.0.3538.77

Issue or Feature Request Description:
I have the following code for enqueuing failed requests

const queue = new workbox.backgroundSync.Queue('api_requests');

self.addEventListener('fetch', (event) => {
    // Clone the request to ensure it's save to read when
    // adding to the Queue.
    const promiseChain = fetch(event.request.clone())
        .catch((err) => {
            return queue.addRequest(event.request);
        });

    event.waitUntil(promiseChain);
});

It successfully enqueues failed requests when I take my machine offline; however, when I bring it back online and sync occurs the request body is sometimes incomplete as if requests were only partially stored (values are empty or truncated). This doesn't occur when using Chrome's offline functionality, only when disconnecting my WIFI.

I haven't figured out how to inspect the body Blob in IndexDB to see if the request is being stored correctly.

@philipwalton
Copy link
Member

...when I bring it back online and sync occurs the request body is sometimes incomplete as if requests were only partially stored (values are empty or truncated).

You said "sometimes incomplete"; have you noticed any commonalities in the situations in which the bodies are (or are not) incomplete? Like perhaps if the body is really long it's always incomplete?

Also, where are you seeing them as incomplete? In DevTools or in your server-side code?

I haven't figured out how to inspect the body Blob in IndexDB to see if the request is being stored correctly.

Could you try experimenting with the v4-alpha-0? In that version I've added convenience methods for adding and removing requests from the queue, so it should be easier to get the request out in your code and log the body to the console or something.

See this PR #1710 for details.

@cacciatc
Copy link
Author

You said "sometimes incomplete"; have you noticed any commonalities in the situations in which the bodies are (or are not) incomplete? Like perhaps if the body is really long it's always incomplete?

Yes, it seems to happen more frequently when there are at least 5 requests in the queue.

Also, where are you seeing them as incomplete? In DevTools or in your server-side code?

Server-side and in the queueDidReplay callback.

Could you try experimenting with the v4-alpha-0? In that version I've added convenience methods for adding and removing requests from the queue, so it should be easier to get the request out in your code and log the body to the console or something.

Yes, I will give it a try this morning.

@cacciatc
Copy link
Author

To be clear you want me to try https://github.com/GoogleChrome/workbox/tree/bg-sync-updates correct? I tried the current 4.0.0 RC and the interface for Queues appears to be the same for the moment.

@cacciatc
Copy link
Author

cacciatc commented Nov 5, 2018

Figured it out. Was a bug with the way we were using navigator.geolocation.getCurrentPosition. In the callback we issued the HTTP request. Disconnected WIFI exacerbated the issue. Thanks for working through it with me and thanks for Workbox!

@cacciatc cacciatc closed this as completed Nov 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants