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

Goroutine leak in when closing a DB #586

Open
omriC-talon opened this issue May 12, 2024 · 0 comments
Open

Goroutine leak in when closing a DB #586

omriC-talon opened this issue May 12, 2024 · 0 comments

Comments

@omriC-talon
Copy link

Describe the bug
Hello there, We are using nutsdb as a local k/v store in our project.
Our use case involves opening the db for a few seconds -> minutes & then closing it.
Over time we notice in our monitors that the number of ongoing goroutines keep increasing:

Screenshot 2024-05-12 at 17 15 00

We manually checked the stack traces & noticed that following goroutines increase in number:

goroutine 1633 [chan receive, 1 minutes]:
github.com/nutsdb/nutsdb.(*DB).doWrites(0xc00061b2c0)
	/go/pkg/mod/github.com/nutsdb/nutsdb@v1.0.4/db.go:349 +0x151
created by github.com/nutsdb/nutsdb.open in goroutine 1606
	/go/pkg/mod/github.com/nutsdb/nutsdb@v1.0.4/db.go:116 +0xb35

We checked this against 2 well known leak detection packages - Both agreed on the leak source.
https://github.com/uber-go/goleak

[Goroutine 25 in state chan receive, with github.com/nutsdb/nutsdb.(*DB).doWrites on top of the stack:
github.com/nutsdb/nutsdb.(*DB).doWrites(0x14000820dc0)
	/Users/ocohen1/go/pkg/mod/github.com/nutsdb/nutsdb@v1.0.4/db.go:349 +0xd4
created by github.com/nutsdb/nutsdb.open in goroutine 23
	/Users/ocohen1/go/pkg/mod/github.com/nutsdb/nutsdb@v1.0.4/db.go:116 +0x6e0
]

https://github.com/fortytw2/leaktest

leaktest.go:132: leaktest: timed out checking goroutines
leaktest.go:150: leaktest: leaked goroutine: goroutine 7 [chan receive]:
    github.com/nutsdb/nutsdb.(*DB).doWrites(0x14000d06000)
    	/Users/ocohen1/go/pkg/mod/github.com/nutsdb/nutsdb@v1.0.4/db.go:349 +0xd4
    created by github.com/nutsdb/nutsdb.open in goroutine 5
    	/Users/ocohen1/go/pkg/mod/github.com/nutsdb/nutsdb@v1.0.4/db.go:116 +0x6e0

To Reproduce
Steps to reproduce the behavior(Be specific!):

  1. Create a simplified test that opens & closes the DB
func Test_Goroutine_Leak(t *testing.T) {
	dbDir, err := os.MkdirTemp("", "state_********")
	require.NoError(t, err)
	defer os.RemoveAll(dbDir)

	db, err := nutsdb.Open(
		nutsdb.DefaultOptions,
		nutsdb.WithDir(dbDir),
	)
	require.NoError(t, err)

	err = db.Close()
	require.NoError(t, err)
}
  1. Use a leak detection tool / manually check the stack trace

Expected behavior
No leftover Goroutines should be alive after calling db.Close()

What actually happens
Goroutines keep running in the background

Screenshots

please complete the following information :

  • OS: Locally on a mac. In production under Alpine linux in a container.
  • NutsDB Version v1.0.4

Additional context

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