senecajs / seneca

A microservices toolkit for Node.js.
http://senecajs.org
MIT License
3.96k stars 313 forks source link

Using a plugin with a Seneca instance passed as an option, crashes the stack #889

Open lilsweetcaligula opened 3 years ago

lilsweetcaligula commented 3 years ago

Ave! I believe I have discovered a bug. When I create a plugin, use it and pass another Seneca instance as an option to the plugin, the code mysteriously crashes the stack:

const Seneca = require('seneca')

function my_plugin(options) {
}

const lambda = Seneca()
const tau = Seneca()

tau.use(my_plugin, { seneca: lambda })

// ERROR: Maximum call stack size exceeded

My Seneca version is at 3.23.3 and it's the only dependency I have in my package.json file.

lilsweetcaligula commented 3 years ago

A quick workaround would be to pass a function wrapping the Seneca instance, instead of passing the Seneca instance directly:

const Seneca = require('seneca')

function my_plugin(options) {
}

const lambda = Seneca()
const tau = Seneca()

tau.use(my_plugin, { seneca: () => lambda })

// OK
lilsweetcaligula commented 3 years ago

I was able to track down the offending line: https://github.com/senecajs/seneca/blob/master/lib/plugin.ts#L554