While creating properties for a model during yo loopback:model I got this error:
Let's add another order property.
Enter an empty property name when done.
[?] Property name: state
invoke loopback:property
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
/home/jeff/.nvm/v0.11.13/lib/node_modules/generator-loopback/node_modules/loopback-workspace/node_modules/longjohn/dist/longjohn.js:185
throw e;
^
Console.trace (console.js:95:17),ReadStream.EventEmitter.addListener (events.js:179:15),ReadStream.Readable.on (_stream_readable.js:667:33),new Interface (readline.js:124:11),Object.exports.createInterface (readline.js:38:10),Object.Interface.createInterface (/home/jeff/.nvm/v0.11.13/lib/node_modules/yo/node_modules/yeoman-generator/node_modules/inquirer/node_modules/readline2/index.js:39:21),PromptUI.UI (/home/jeff/.nvm/v0.11.13/lib/node_modules/yo/node_modules/yeoman-generator/node_modules/inquirer/lib/ui/baseUI.js:23:40),new PromptUI (/home/jeff/.nvm/v0.11.13/lib/node_modules/yo/node_modules/yeoman-generator/node_modules/inquirer/lib/ui/prompt.js:26:8)
Thanks
Clean 14.04 server x64
NodeJS 0.11.13
--> installed with nvm 0.12.1
npm 1.4.9
yo 1.2
I am not able to reproduce the problem. How many properties have you added to your model this way? Do you get the same error when running yo loopback:property?
BTW v1.1.0 of yo loopback uses a newer version of yeoman-generator which introduced a bug that prevents yo loopback:model from running yo loopback:property: https://github.com/yeoman/generator/issues/589
The workaround is to repeatedly call yo loopback:property from command-line.
Hi @bajtos, I just had 4 or 5 properties built, was attempting another one...
Thanks for the info, strange though because it did seem like I ran the yo loopback:property couple times just fine before it broke...
There seems to be a second place where this error arises:
$ slc run
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at EventEmitter.addListener (events.js:179:15)
at EventEmitter.once (events.js:204:8)
at createListener (.../central/node_modules/loopback-datasource-juggler/lib/datasource.js:395:19)
at DataSource.defineRelations (.../central/node_modules/loopback-datasource-juggler/lib/datasource.js:443:9)
at DataSource.setupDataAccess (.../central/node_modules/loopback-datasource-juggler/lib/datasource.js:491:8)
at DataSource.attach (.../central/node_modules/loopback-datasource-juggler/lib/datasource.js:702:8)
at Function.ModelClass.attachTo (.../central/node_modules/loopback-datasource-juggler/lib/model-builder.js:278:16)
at Object.registry.configureModel (.../central/node_modules/loopback/lib/registry.js:173:15)
at configureModel (.../dev/central/node_modules/loopback/lib/application.js:401:12)
at Function.app.model (.../dev/central/node_modules/loopback/lib/application.js:139:5)
Browse your REST API at http://localhost:3000/explorer
Web server listening at: http://localhost:3000/
However, in this case execution continues just fine... no crash
How many relations do you have? The code is trying to set up once listeners so that relations can be configured after the model has been attached to a data source. Maybe we should increase the max number of listeners in this case.
Oh.. lots of relations indeed. I've been looking for how to increase that number but what is it by default?
I'll increase the max listeners in base model class that functions as the event emitter.
Great thanks!
The fix was released in loopback v2.2.0.
@bajtos @raymondfeng
I am still facing the issue. Is loopback trying to generate all the APIs at the boot because its is very slow or it is looking the model-config.json to generate APIs for the public api only?
[2015-06-24 13:53:13.218] [ERROR] console - (node) warning: possible EventEmitter memory leak detected. 33 dataAccessConfigured listeners added. Use emitter.setMaxListeners() to increase limit.
[2015-06-24 13:53:13.221] [ERROR] console - Trace
at EventEmitter.addListener (events.js:179:15)
at EventEmitter.once (events.js:204:8)
at createListener (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/datasource.js:410:19)
at /Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/datasource.js:472:9
at Array.forEach (native)
at DataSource.defineRelations (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/datasource.js:442:28)
at DataSource.setupDataAccess (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/datasource.js:521:8)
at DataSource.attach (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/datasource.js:737:8)
at Function.ModelClass.attachTo (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/model-builder.js:331:16)
at Registry.configureModel (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback/lib/registry.js:238:15)
at configureModel (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback/lib/application.js:411:16)
at EventEmitter.app.model (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback/lib/application.js:132:5)
at /Users/Coderider/TCM/Dev/api-server/node_modules/loopback-boot/lib/executor.js:172:9
at Array.forEach (native)
at setupModels (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-boot/lib/executor.js:168:23)
at execute (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-boot/lib/executor.js:32:3)
INFO strong-agent not profiling, agent metrics requires a valid license.
Please contact [email protected] for assistance.
I have lot of Models around 700 and lots of relations. When I had around 500 models it was working now suddnly it is also throwing errors like this Not sure if it is related.
{
error: {
name: "TypeError"
status: 500
message: "Cannot read property 'type' of undefined"
stack: "TypeError: Cannot read property 'type' of undefined at MsSQL.toDatabase (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-connector-mssql/lib/mssql.js:497:11) at /Users/Coderider/TCM/Dev/api-server/node_modules/loopback-connector-mssql/lib/mssql.js:786:20 at Array.forEach (native) at MsSQL._buildWhere (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-connector-mssql/lib/mssql.js:770:22) at MsSQL.buildWhere (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-connector-mssql/lib/mssql.js:854:20) at MsSQL.all (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-connector-mssql/lib/mssql.js:666:17) at /Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/dao.js:1399:19 at doNotify (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/observer.js:93:49) at doNotify (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/observer.js:93:49) at doNotify (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/observer.js:93:49) at doNotify (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/observer.js:93:49) at Function.ObserverMixin._notifyBaseObservers (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/observer.js:116:5) at Function.ObserverMixin.notifyObserversOf (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/observer.js:91:8) at Function.ObserverMixin._notifyBaseObservers (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/observer.js:114:15) at Function.ObserverMixin.notifyObserversOf (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/observer.js:91:8) at Function.ObserverMixin._notifyBaseObservers (/Users/Coderider/TCM/Dev/api-server/node_modules/loopback-datasource-juggler/lib/observer.js:114:15)"
}-
}
@f0ysal If you are using [email protected], then it loads all models configured in model-config.json, regardless of whether they are public or not.
Regarding possible EventEmitter memory leak detected, please open a new GH issue and provide specific steps how we can reproduce the problem ourselves.
Regarding TypeError: Cannot read property 'type' of undefined at MsSQL.toDatabase, this may be a bug caused by recent changes in the connector, please open a new GH issue in loopback-connector-mssql.
For the EventEmitter warning, it is expected in your case as there are many relations. We use the event listener to wait for related models to be loaded before creating relations. We could increase the number of max listeners to disable the warning.
For the TypeError, most likely you need to run npm up to update the dependencies.
How and where to set emitter. setMaxListeners ? Please help
setMaxListeners is hard-coded here. For our purposes (I work with Foysal) we do fine by increasing this to 64. I guess it should be configurable?
@zamb3zi Would you like to submit a PR?
I am encountering this too, and after looking a bit into what's causing it, here my assessment:
When using async functions in auto-migration, the used data-sources will end up observing as many 'connected' events as there are models, because of these lines here in SQLConnector:
if (!this.dataSource.connected) {
return this.dataSource.once('connected', function() {
self.execute(sql, params, options, callback);
});
}
Here a simple solution to prevent the error while still having a reasonable value for the maximum of listeners:
const numModels = Object.keys(app.models).length
for (let dataSource of Object.values(app.dataSources)) {
dataSource.setMaxListeners(numModels)
}
Perhaps it is worth putting something like this into LoopBack itself?
Perhaps it is worth putting something like this into LoopBack itself?
That makes sense to me. I think you should use something like this to obtain the number of models possible associated with a datasource:
Object.keys(dataSource.models).length;
Few alternatives:
Most helpful comment
setMaxListenersis hard-coded here. For our purposes (I work with Foysal) we do fine by increasing this to 64. I guess it should be configurable?