1

sorry for my bad english :-)

I have a problem I can't actually not really explain.

I use these versions of angular right now: @angular/*: 4.4.6 (Meaning also the @angular/http: 4.4.6 package).

I use RxJS to do http GET request like this one:

import {EventEmitter, Injectable} from '@angular/core';
import {Headers, Http} from '@angular/http';

@Injectable()
export class DataService {

//SOME-CODE

constructor(private _http: Http) {
    //SOME-CODE
}

getStatus() {
    const headers = new Headers({
        'Content-Type': 'application/json'
    });

    return new Promise((resolve, reject) => {
        return  this._http.get(
                    'https://[URL]:[PORT]/[PATH]',
                    {headers: headers}
                ).map(
                    (res) => res.json()
                ).toPromise()
                .then(
                    (res) => {
                        if (/*SOME-CONDITION*/) {
                            return true;
                        }else{
                            return false;
                        }

                        resolve();
                    }
                ).catch(
                    e => {
                        //ERROR-HANDLING
                        return false;
                    }
                );
        }
    }
}

The request seems to work fine for some browser-sessions but after a while (I cannot tell exactly when) at a certain point when angular app is reloaded/called again after the initial loading the http request gets stuck and browser freezes because of high CPU usage.

My debugging efforts so far:

  • It happens at Android, Chrome Browser, Firefox, Safari.
  • When using incognito mode in Chrome f.e. it's works, no freezing.
  • When using chrome debugging tools and looking into 'network' activities you'll see the 'pending' status on that specific request. When trying to see whats the request header you'll getting a black page in that window where normally informations should be displayed.
  • Looking into 'Application' like LocalStorage or cookies there's no hint (f.e. LocalStorage exceeded or cookies being cached).
  • When looking into server (simple nodejs webserver) who will provide a response, no request at all comes in.
  • I tried to use an another service like "https://jsonplaceholder.typicode.com/" to be sure it's not my server who is not working properly. Same behavior here.
  • I tried to use 'Performance' tool from chrome which is really hard to get a snapshot cause CPU freezes fast. Although I made it a few times all I could see was a lot of event firing and zone.js stuff. Nothing special to debug there. Fair to say that I am not an expert to debug internal angular processes.
  • Then I tried kicking out every module which I don't need at this dataService. No luck.
  • Finally I used a simple XMLHttpRequest() to avoid the angular http module. Nothing changed. Request obviously fired but pending with freeze.

If you're giving up at a certain point and delete Browser cache (f.e. in chrome) and reload the app it's working again.

Does anyone had this kind of issue or was dealing with it? I am going crazy here :-(

Thanks for helping.

user3332010
  • 147
  • 1
  • 11
  • 1
    That repeated promisifying seems very complex for no good reason, have you tried seeing if the problem remains if you don't do that? – jonrsharpe Apr 25 '18 at 08:16
  • 2
    `Http` is deprecated you should use `HttpClient`, https://stackoverflow.com/questions/45129790/difference-between-http-and-httpclient-in-angular-4 – mxr7350 Apr 25 '18 at 08:18
  • have you tried to see whats going on on your server when request 'freezes'? also, if you prefer to use promise instead of rxjs, may be it will be good for you to use native "fetch" (it also returrns promise) – happyZZR1400 Apr 25 '18 at 08:56
  • @jonrsharpe Yes, by using a simple XHR request (js plain) as described in my efforts. Do you have an another option to wait for a response from http request instead of using promise? I need to wait for a response until I can decide in my code what will happen. – user3332010 Apr 25 '18 at 11:02
  • @mxr7350 Thanks for the hint. Would that also solve my problem or better say do you had any trouble like me using http request synchronously? – user3332010 Apr 25 '18 at 11:04
  • @happyZZR1400 Yes, I looked at the nodejs server if any request are recognized as described in my efforts. But no Luck there. And for myself I also prooved that it's not my server who is not responding/working. Any other idea? :-) – user3332010 Apr 25 '18 at 11:07
  • No more answer from anyone? :-) – user3332010 Apr 29 '18 at 05:02
  • @user3332010 I see same issue with my Angular 10 application, some http requests just freeze, my server doesn't receive any requests by that time. I have to refresh the page and the same request works. It happens sometimes, randomly with different endpoints. Were you able to manage it? – 0bj3ct Sep 13 '21 at 19:41

0 Answers0