Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating deep services fails #75

Open
viters opened this issue Jul 25, 2023 · 1 comment
Open

Creating deep services fails #75

viters opened this issue Jul 25, 2023 · 1 comment

Comments

@viters
Copy link

viters commented Jul 25, 2023

From docs:

Any depth of injection is supported (ServiceA can depend on ServiceB which depends on ServiceC and so on). A service can also depend on as many services as it would like (ServiceA can depend on service D, E and F etc). Howerver, services cannot have circular dependencies.

Creating larger than 7-depth services fails: https://go.dev/play/p/QwAmt1aIbiE

panic: 1. write lock is not held by this thread
2. an error occurred while getting the dependencies of default#Component3.1.5
3. an error occurred while getting the dependencies of default#Component4.1.6
4. an error occurred while getting the dependencies of default#Component5.1.7
5. an error occurred while getting the dependencies of default#Component6.1.8
6. an error occurred while getting the dependencies of default#Component7.1.9
7. an error occurred while getting the dependencies of default#Component8.1.10

goroutine 1 [running]:
main.main()
	/tmp/sandbox741982879/prog.go:58 +0xa5

In real-project we also experienced IOC error: function called from non-goethe thread and sometimes code just hangs on goethe lock acquire in gotethe cache/cache.go:243.

Workaround

If the depth of creation is smaller (ex. something existed previously), it works: https://go.dev/play/p/SVmmLqr3_6I

@viters
Copy link
Author

viters commented Jul 27, 2023

The problem seems to be caused by GetThreadID in goethe_factory.

When creating services 8 to 2, TID is correctly calculated as 22. There are two xXTidFrame in stacktrace:

	/Users/lukaszszczesniak/go/pkg/mod/github.com/jwells131313/[email protected]/reflection_utilities.go:94 +0xa8
github.com/jwells131313/goethe.invokeEnd(0x16, {0x104e1d880, 0xc0000999c0}, {0xc0001babd0, 0x2, 0x2})
	/Users/lukaszszczesniak/go/pkg/mod/github.com/jwells131313/[email protected]/goethe_factory.go:447 +0x170
github.com/jwells131313/goethe.internalInvoke(0x16, 0x2, {0xc0000a7868, 0x2, 0x8}, {0x104e1d880, 0xc0000999c0}, {0xc0001babd0, 0x2, 0x2})
	/Users/lukaszszczesniak/go/pkg/mod/github.com/jwells131313/[email protected]/goethe_factory.go:454 +0xb0
github.com/jwells131313/goethe.xXTidFrame6(0x16, 0x1, {0xc0000a7868, 0x2, 0x8}, {0x104e1d880, 0xc0000999c0}, {0xc0001babd0, 0x2, 0x2})
	/Users/lukaszszczesniak/go/pkg/mod/github.com/jwells131313/[email protected]/goethe_factory.go:523 +0xc8
github.com/jwells131313/goethe.internalInvoke(0x16, 0x1, {0xc0000a7868, 0x2, 0x8}, {0x104e1d880, 0xc0000999c0}, {0xc0001babd0, 0x2, 0x2})
	/Users/lukaszszczesniak/go/pkg/mod/github.com/jwells131313/[email protected]/goethe_factory.go:472 +0x5e4
github.com/jwells131313/goethe.xXTidFrame1(0x16, 0x0, {0xc0000a7868, 0x2, 0x8}, {0x104e1d880, 0xc0000999c0}, {0xc0001babd0, 0x2, 0x2})
	/Users/lukaszszczesniak/go/pkg/mod/github.com/jwells131313/[email protected]/goethe_factory.go:503 +0xc8
github.com/jwells131313/goethe.internalInvoke(0x16, 0x0, {0xc0000a7868, 0x2, 0x8}, {0x104e1d880, 0xc0000999c0}, {0xc0001babd0, 0x2, 0x2})
	/Users/lukaszszczesniak/go/pkg/mod/github.com/jwells131313/[email protected]/goethe_factory.go:462 +0x278
github.com/jwells131313/goethe.invokeStart(0x16, {0x104e1d880, 0xc0000999c0}, {0xc0001babd0, 0x2, 0x2})
	/Users/lukaszszczesniak/go/pkg/mod/github.com/jwells131313/[email protected]/goethe_factory.go:441 +0xd0
created by github.com/jwells131313/goethe.(*StandardThreadUtilities).Go
	/Users/lukaszszczesniak/go/pkg/mod/github.com/jwells131313/[email protected]/goethe_factory.go:155 +0x404

On next recursion, when creating service 1, TID is calculated as 6, there is only one xXTidFrame in stacktrace:

image

I thought that maybe debug.Stack() is not returning everything but it does seem to. Maybe the recursive lock is not ready to handle 8 write recursions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant