seneca icon indicating copy to clipboard operation
seneca copied to clipboard

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

Open lilsweetcaligula opened this issue 3 years ago • 2 comments

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 avatar Sep 15 '21 06:09 lilsweetcaligula

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 avatar Sep 15 '21 06:09 lilsweetcaligula

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

lilsweetcaligula avatar Sep 15 '21 07:09 lilsweetcaligula