feathersjs-ecosystem / client

[MOVED] Client side Feathers build
https://github.com/feathersjs/feathers
MIT License
111 stars 27 forks source link

EventEmitter memory leak detected #236

Closed dottodot closed 6 years ago

dottodot commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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