Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

EventEmitter memory leak detected #236

Closed
dottodot opened this issue Jan 7, 2018 · 2 comments
Closed

EventEmitter memory leak detected #236

dottodot opened this issue Jan 7, 2018 · 2 comments

Comments

@dottodot
Copy link

dottodot commented Jan 7, 2018

In my Angular app I've started to get the following error in certain circumstances and not sure why.

feathers.js:2685 (node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.

My page has next and prev links that allow me to navigate to the next gallery but after the 11th navigation it gives the error. In my component below I'm just subscribing to the route change to then fetch the next or previous item

export class GalleryDetailComponent implements OnInit, OnDestroy {
  gallery$: Observable<any>;
  constructor(private service: ApiService, private route: ActivatedRoute) {
    service.setup('gallery');
  }

  ngOnInit() {
    this.getGallery();
  }

  getGallery() {
    this.gallery$ = this.route.params.pipe(
      switchMap((params: any) => {
        return this.service.get(params['slug']);
      })
    );
  }

  ngOnDestroy() {}
}

and this is my feathers service and api service.

@Injectable()
export class FeathersService {
  private _feathers: any;
  private _rest: any;
  constructor(public http: HttpClient) {
    this._rest = rest(environment.host);
    this._feathers = feathers();
    this._feathers.configure(
      authentication({
        storageKey: 'auth-token',
        storage: new CookieStorage({
          path: '/',
          expires: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000)
        })
      })
    );
    this._feathers.configure(
      this._rest.angularHttpClient(this.http, { HttpHeaders: HttpHeaders })
    );
    this._feathers.configure(
      feathersRx({
        listStrategy: 'always',
        idField: '_id'
      })
    );
  }

  // expose services
  public service(name: string) {
    return this._feathers.service(name);
  }
}

@Injectable()
export class ApiService {
  private service: any;
  constructor(private feathers: FeathersService) {}

  setup(endpoint: string) {
    this.service = this.feathers.service(endpoint);
  }

  get(id: number | string, query?: any) {
    return this.service.watch({ strategy: 'always' }).get(id, { query: query });
  }
}
@daffl
Copy link
Member

daffl commented Jan 7, 2018

I think this is an issue with https://github.com/feathersjs-ecosystem/feathers-reactive but the cached observables should be cleared out when nothing is subscribing to them anymore.

@daffl
Copy link
Member

daffl commented Jan 12, 2018

I'm going to close this as a duplicate of feathersjs-ecosystem/feathers-reactive#88, we'll keep track of it over there since it is a feathers-reactive issue.

@daffl daffl closed this as completed Jan 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants