dingo icon indicating copy to clipboard operation
dingo copied to clipboard

Deadlock in SingletonScope for circular dependencies

Open bastianccm opened this issue 5 years ago • 0 comments

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))
}

bastianccm avatar May 20 '19 08:05 bastianccm