Parse-SDK-JS icon indicating copy to clipboard operation
Parse-SDK-JS copied to clipboard

Promise is never resolved when a server is down

Open igor-lemon opened this issue 4 years ago • 7 comments

New Issue Checklist

Issue Description

The Promise from RESTController will never resolved when a server is down.

Steps to reproduce

Set some wrong URL as parse server url , parse.serverURL = 'https://some-wrong-site.com' Call

 const parseConfig = await Parse.Config.get()

Actual Outcome

The promise will never resolve.

Expected Outcome

The promise should be rejected.

Environment

Client

  • Parse JS SDK version: 3.3.1

igor-lemon avatar Sep 29 '21 00:09 igor-lemon

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

What would be the expectation? To reject the promise after a timeout? I would assume the JS SDK already has a retry/timeout mechanism in place in case of bad network connection.

mtrezza avatar Sep 29 '21 10:09 mtrezza

Yep, I think we should make a few retries (if I remember 5 by default) but after the promise should be rejected. We have infinity waiting at the moment.

I think it related with if (xhr.readyState !== 4 || handled || xhr._aborted) condition. We have xhr.readyState === 1 and just exit from the handler and after we don't make any repeat attempts. I solved it at the local build when reject the promise at RESTControlle.js

 if (xhr.readyState !== 4 || handled || xhr._aborted) {
   promise.reject(xhr);
 }

igor-lemon avatar Sep 29 '21 11:09 igor-lemon

Sounds reasonable. Do you think you can submit a PR with a test and a fix for this?

mtrezza avatar Sep 29 '21 14:09 mtrezza

Yep. I'll try to do it today

igor-lemon avatar Sep 29 '21 15:09 igor-lemon

Hi, @mtrezza! Will you check the PR?

igor-lemon avatar Sep 30 '21 20:09 igor-lemon

Sure, feel free to request a review inside the PR anytime.

mtrezza avatar Sep 30 '21 21:09 mtrezza