Skip to content

rxjs subscription leak in DowngradeComponentAdapter.subscribeToOutput #48032

Closed

Description

@vbraun

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

Destroying a downgraded component with @Output leaks a rxjs subscription

Steps to reproduce:

  • You need an Angular component with an @Output
  • Downgrade to use it in an AngularJS component
  • Create & destroy the downgraded component, e.g. by routing to a page that contains it and then routing away

In https://github.com/angular/angular/blob/main/packages/upgrade/src/common/src/downgrade_component_adapter.ts:

  private subscribeToOutput(output: PropertyBinding, expr: string, isAssignment: boolean = false) {
    const getter = this.$parse(expr);
    const setter = getter.assign;
    if (isAssignment && !setter) {
      throw new Error(`Expression '${expr}' is not assignable!`);
    }
    const emitter = this.component[output.prop] as EventEmitter<any>;
    if (emitter) {
      emitter.subscribe({                            <------------- this subscription is never unsubscribed from 
        next: isAssignment ? (v: any) => setter!(this.scope, v) :
                             (v: any) => getter(this.scope, {'$event': v})
      });
    } else {
      throw new Error(`Missing emitter '${output.prop}' on component '${
          getTypeName(this.componentFactory.componentType)}'!`);
    }
  }

The subscription leak might be garbage collectable depending on how the @Output observable is defined, our leak check tooling cannot test that programatically. In any case a user could have defined the @Output to be a long-lived observable, in which this is a genuine leak.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 14.2.9
Node: 16.15.0
Package Manager: npm 8.5.5 
OS: linux x64

Angular: 14.2.10
... animations, common, compiler, compiler-cli, core, elements
... forms, language-service, localize, platform-browser
... platform-browser-dynamic, router, upgrade

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1402.9
@angular-devkit/build-angular   14.2.9
@angular-devkit/core            14.2.9
@angular-devkit/schematics      13.3.5
@angular/cdk                    14.2.7
@angular/cli                    14.2.9
@angular/material               14.2.7
@schematics/angular             14.2.9
ng-packagr                      14.1.0
rxjs                            6.6.7
typescript                      4.7.4

Anything else?

No response

Activity

  1. added
    area: upgrade
    on Nov 11, 2022
  2. added this to the needsTriage milestone on Nov 11, 2022
  3. added
    P3
    on Nov 16, 2022
  4. modified the milestones: needsTriage, Backlog on Nov 16, 2022
  5. added a commit that references this issue on Jul 11, 2023
    3efb577
  6. added a commit that references this issue on Jul 26, 2023
    3998970
  7. angular-automatic-lock-bot commented on Aug 11, 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.

  8. locked and limited conversation to collaborators on Aug 11, 2023
  9. added a commit that references this issue on Jan 23, 2024
    f58903b
  10. added a commit that references this issue on Jun 6, 2024
    253d756
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area: upgrade

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions