Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Infinite loop instead of error when misconfigured #147

Open
nbarbettini opened this issue May 6, 2016 · 3 comments · May be fixed by #193
Open

Infinite loop instead of error when misconfigured #147

nbarbettini opened this issue May 6, 2016 · 3 comments · May be fixed by #193

Comments

@nbarbettini
Copy link
Member

nbarbettini commented May 6, 2016

This was found by a customer and repro'ed by me. This is a hard-to-discover hang that happens in a CORS scenario when STORMPATH_CONFIG.ENDPOINT_PREFIX is not configured.

Repro branch: https://github.com/nbarbettini/StormpathAuth/tree/hang-repro/Client
This should get the sample client running, no server required:

npm install && bower install
gulp serve-dev

What's happening is this:

  1. Because STORMPATH_CONFIG.ENDPOINT_PREFIX isn't pointing to the remote server, the call to /me in UserService.prototype.get is requesting localhost:3000/me, which succeeds and returns index.html
  2. self.currentUser = new User(response.data.account || response.data) doesn't fail but stuffs index.html into currentUser
  3. When a state change to /login is detected, this block causes an infinite loop because $user.currentUser.href never exists:
              $user.get().finally(function(){
                if($user.currentUser && $user.currentUser.href){
                  $state.go(config.defaultPostLoginState);
                } else {
                  $state.go(toState.name,toParams);
                }
              });

This could partially be solved by doing a sanity check in UserService.prototype.get:

            if (!response.headers('Content-Type').startsWith('application/json')) {
              op.reject(response);
              return op.promise;
            }

This doesn't totally solve the problem, though, because finally is ignoring whether the request succeeds or fails.

Configuring STORMPATH_CONFIG.ENDPOINT_PREFIX fixes the problem, but I'm reporting this because I think the failure mode could be better in this case - hanging is hard to diagnose.

@nbarbettini nbarbettini added the bug label May 6, 2016
@nbarbettini
Copy link
Member Author

nbarbettini commented May 6, 2016

Happy to help on this one if the repro steps are confusing.

@surfjedi
Copy link

+1

@robertjd
Copy link
Member

Thanks for the report, this is something we'll fix.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants