0

I have an Angular (9) frontend with nestjs backend rest api (in nodejs) The endpoint I call in the backend does some fairly complex operations and it takes about 2 min to respond. In the frontend I use subscribe to subscribe to the response like this:

this.metaService.subscribe(
  result => {
  //Handle result
  },
  error => {
    this.subscription.unsubscribe();
    console.error('Error: ' + error);
  },
  () => {
    this.subscription.unsubscribe();
    console.error('Completed');
  });

The problem is that in the backend it starts executing code over and over again. Note that it does not execute the http call again (I can see this from the network tab in Developer tools), it stays in Pending all the time) It seems this works if I do

.pipe(take(1)).subscribe(

then it does not do the looping in the backend but it immediately completes the subscription (and the http is in cancelled state in network tab) I am running this in my localhost on a windows machine (linux subsystem). Node version is 12.14.1

Does anyone what is causing this and how to fix it ?

-Jani

jani_r
  • 637
  • 1
  • 7
  • 18
  • Can you post your NestJS route handler code? If there's no subsequent network request it sounds like the error is in the API. If the request is being cancelled from Angular when using the `take(1)` then that could cause what would have been a loop, to stop. – Tobin Feb 26 '20 at 16:34
  • This is the controller, https://codeshare.io/5wRZpx retrieveMetadataForCompare retums a Promise and it has a middleware configured which sets the uid – jani_r Feb 26 '20 at 18:27

1 Answers1

0

This is not the answer: I think I was able to figure this out. I had several static async methods in a for loop which seemed to be causing this. I don't really now why but when I removed the methods and converted them to non-static async methods (still in for loop) I am not experiencing the issue anymore. I am not sure why they were static in the first place...

jani_r
  • 637
  • 1
  • 7
  • 18