Skip to content

Cyclic dependency detection #110

Open
@pixtim

Description

@pixtim

It looks like the container crashes with a stack-overflow when a cyclic dependancy has been configured.


internal/console/constructor.js:241,
    if (isStackOverflowError(e)),
        ^

RangeError: Maximum call stack size exceeded,
    at Object.Console.<computed> (internal/console/constructor.js:241:9),
    at Object.log (internal/console/constructor.js:282:26),
    at Container.symbol2string (/scm/hex/packages/sector/node_modules/container-ioc/dist/lib/container.js:142:17),
    at Container.getTokenString (/scm/hex/packages/sector/node_modules/container-ioc/dist/lib/container.js:134:25),
    at Container.buildTraceMessage (/scm/hex/packages/sector/node_modules/container-ioc/dist/lib/container.js:126:31),
    at Container.resolveInternal (/scm/hex/packages/sector/node_modules/container-ioc/dist/lib/container.js:36:29),
    at /scm/hex/packages/sector/node_modules/container-ioc/dist/lib/container.js:99:74,
    at Array.map (<anonymous>),
    at Container.instantiateWithFactory (/scm/hex/packages/sector/node_modules/container-ioc/dist/lib/container.js:99:47),
    at Container.resolveInternal (/scm/hex/packages/sector/node_modules/container-ioc/dist/lib/container.js:47:31),
    at /scm/hex/packages/sector/node_modules/container-ioc/dist/lib/container.js:99:74,
    at Array.map (<anonymous>),
    at Container.instantiateWithFactory (/scm/hex/packages/sector/node_modules/container-ioc/dist/lib/container.js:99:47),
    at Container.resolveInternal (/scm/hex/packages/sector/node_modules/container-ioc/dist/lib/container.js:47:31),
    at /scm/hex/packages/sector/node_modules/container-ioc/dist/lib/container.js:99:74,
    at Array.map (<anonymous>)

This can be reproduced by creating services A and B with their corresponding tokens and cross-injecting them:

provide service A
provide service B
A injects B
B injects A

I've worked around this issue in my project by avoid cyclic dependencies. Please let me know if you'd like me to create a minimal reproduction.

Thanks for the awesome package. It's helping a lot! 🦄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions