Skip to content

HTTP calls seem to hang server side only #50405

Closed

Description

@CarlosTorrecillas

🐞 Bug report

What modules are related to this issue?

  • builders
  • common
  • express-engine

Is this a regression?

I think this is a regression compared to the previous version I got installed which was 15.2.7

Description

HTTP calls seem to get stuck and do not finish serverside when they go out externally (to a real API).

🔬 Minimal Reproduction

1.- Download the finished example that is available in the Angular site: https://angular.io/guide/universal which is the tour of heroes
2.- Go to the app.module.ts and comment out the HttpClientInMemoryWebApiModule so that it simulates that there is a real HTTP call.
3.- Run the code using npm run dev:ssr for example
4.- Navigate to http://localhost:4200/dashboard
5.- See in the page that you have the Messages, the clear button and there is one message saying: HeroService: getHeroes failed: Http failure response for http://localhost:4200/api/heroes: 404 Not Found
6.- Right click on the page and click on View Page Source and see that all static code that needs to be rendered pre-HTTP call gets rendered on the page such as the Tour of Heroes, the Dashboard tab or the heroes tab is rendered however things like the Messages section (H2) or the actual message itself is not.

🔥 Exception or Error

I can see the following error in logs of the server

NetworkError
    at send (./node_modules/xhr2/lib/xhr2.js:281:19)
    at observer (./node_modules/@angular/common/fesm2022/http.mjs:1969:21)
    at _trySubscribe (./node_modules/rxjs/dist/cjs/internal/Observable.js:41:25)
    at cb (./node_modules/rxjs/dist/cjs/internal/Observable.js:35:31)
    at errorContext (./node_modules/rxjs/dist/cjs/internal/util/errorContext.js:22:9)
    at subscribe (./node_modules/rxjs/dist/cjs/internal/Observable.js:26:24)
    at onNext (./node_modules/rxjs/dist/cjs/internal/operators/switchMap.js:17:63)
    at _next (./node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:33:21)
    at next (./node_modules/rxjs/dist/cjs/internal/Subscriber.js:51:18)
    at <anonymous> (./node_modules/rxjs/dist/cjs/internal/observable/innerFrom.js:120:28)

However although the error (I am not sure) is related to a real 404, that should be handled in the application and the message should be rendered.

🌍 Your Environment



     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 16.0.2
Node: 18.10.0
Package Manager: npm 8.19.2
OS: win32 x64

Angular: 16.0.2
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1600.2
@angular-devkit/build-angular   16.0.2
@angular-devkit/core            16.0.2
@angular-devkit/schematics      16.0.2
@nguniversal/builders           16.0.2
@nguniversal/express-engine     16.0.2
@schematics/angular             16.0.2
rxjs                            7.8.1
typescript                      4.9.5

Activity

  1. matthew-whitfield-uk commented on May 20, 2023

    @matthew-whitfield-uk

    I have also been experiencing issues with server-side HTTP calls when upgrading from 16.0.0-rc.0 to 16.0.2.

    The HTML rendered on the server side by angular universal doesn't seem to wait for HTTP calls to complete before sending the HTML to the user. The affects things like TransferState, which can store an HTTP response in the rendered HTML for the user to pick up, but in 16.0.2 it doesn't get included in the HTML.

    It only seems to affect lazy loaded routes, the main AppModule component will wait for HTTP calls / setTimeoutes etc to complete before rendering the page and sending it to the user. However, any lazy-loaded routes won't wait, and so the server-rendered HTML won't include the results of any such requests.

    Beforehand, angular universal would wait for these to complete on all routes before building the page.

    Not sure if separate issue, or if this is some new config I am missing with the upgrade.

  2. jvyden commented on May 20, 2023

    @jvyden

    Getting a similar issue to Matthew, with the notable exception that in addition to not seeing the elements in the HTML I get an error in console upon page render depending on the request I make:

    RuntimeError: NG0205: Injector has already been destroyed.
        at assertNotDestroyed (./node_modules/@angular/core/fesm2022/core.mjs:9201:19)
        at runInContext (./node_modules/@angular/core/fesm2022/core.mjs:9093:14)
        at chain (./node_modules/@angular/common/fesm2022/http.mjs:1399:57)
        at handle (./node_modules/@angular/common/fesm2022/http.mjs:1454:21)
        at req (./node_modules/@angular/common/fesm2022/http.mjs:1226:70)
        at doInnerSub (./node_modules/rxjs/dist/cjs/internal/operators/mergeInternals.js:22:31)
        at onNext (./node_modules/rxjs/dist/cjs/internal/operators/mergeInternals.js:17:70)
        at _next (./node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:33:21)
        at next (./node_modules/rxjs/dist/cjs/internal/Subscriber.js:51:18)
        at Observable._subscribe (./node_modules/rxjs/dist/cjs/internal/observable/innerFrom.js:109:24) {

    Interestingly, if I try to log the result in a request's observer that doesn't fire this error, the result appears as expected:
    image

  3. CarlosTorrecillas commented on May 21, 2023

    @CarlosTorrecillas
    Author

    @matthew-whitfield-uk that fits into the behavior I am seeing. The information I don't know about is "what happens" to the actual HTTP request since my logs (on another application) does not show anything. Hopefully we get some feedback soon from the Angular team - since that's for me is a blocker for the upgrade

  4. alan-agius4 commented on May 22, 2023

    @alan-agius4
    Contributor

    I actually managed to replicate the problem and I am looking into it.

  5. added
    needs reproduction
    area: server
    on May 22, 2023
  6. modified the milestone: Backlog on May 22, 2023
  7. CarlosTorrecillas commented on May 22, 2023

    @CarlosTorrecillas
    Author

    I have the repo ready for you in case you wanted: https://github.com/CarlosTorrecillas/universal-issue but seems you are already on it. Thanks @alan-agius4 !

  8. added
    regression
    on May 22, 2023
  9. removed
    needs reproduction
    on May 22, 2023
  10. modified the milestones: Backlog, needsTriage on May 22, 2023
  11. CarlosTorrecillas commented on May 24, 2023

    @CarlosTorrecillas
    Author

    Do you have an ETA for this code to be merged? It is just from the upgrade planning perspective to get an idea of when this can be available. Thanks a lot!

  12. added a commit that references this issue on May 24, 2023
    080bbd2
  13. alan-agius4 commented on May 24, 2023

    @alan-agius4
    Contributor

    The fix for this should be released on NPM later today.

  14. angular-automatic-lock-bot commented on Jun 24, 2023

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  15. locked and limited conversation to collaborators on Jun 24, 2023
  16. added a commit that references this issue on Jan 23, 2024
    af7b2af
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: serverregression

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions