Skip to content

Deadlock in SingletonScope for circular dependencies #10

Open
@bastianccm

Description

The Circular Dependency check is unable to detect circular dependencies in singletons, as the Singleton will deadlock before the detection happens.

Testcase:

type circSingletonA struct {
	B *circSingletonB `inject:""`
}
type circSingletonB struct {
	A *circSingletonA `inject:""`
}

func TestCircularSingletonBinding(t *testing.T) {
	EnableCircularTracing()
	defer func() {
		traceCircular = nil
	}()
	injector := NewInjector()
	injector.Bind(new(circSingletonA)).In(Singleton)
	injector.GetInstance(new(circSingletonA))
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions