256dpi / lungo

A MongoDB compatible embeddable database and toolkit for Go.
MIT License
462 stars 15 forks source link

Piling up Goroutine #14

Closed azukaar closed 7 months ago

azukaar commented 7 months ago

Hi! First of thanks for this awesome project. I have been using it but I am getting an issue with piling goroutine. This is an example after a few minutes where I have a hundred routine going already image

This is how I use Lungo:

https://github.com/azukaar/Cosmos-Server/blob/master/src/utils/db.go#L128

And then I close the connection this way:

https://github.com/azukaar/Cosmos-Server/blob/master/src/user/list.go#L27

Apologies, it's probably user error but it seems I am closing the connection properly so any help appreciated, thanks!

256dpi commented 7 months ago

Thanks for the report, I found the goroutine leak and fixed it!

I would not recommend to open a lungo database per request, and instead open one globally and share the client among request handlers. Lungo does not support parallel writes to the same database file as for example SQLite does.

azukaar commented 7 months ago

Yep that's what I ended up doing actually, which obviously also fixed the leak since there was a single connection I was just doing it that way initially because I was worried about staling the connection, and writing to nothing without properly handling errors (ex. file disappeared or something) thanks for the fix!