Generated FindAll() function leaks database connections
qJkee opened this issue · 8 comments
Hi! Right now, after using go-kallax, I've got idle connections, which is waiting for client read.
Any ideas why? It's just a simple select for the entity, but it's blocking all application.
So, that mean, that connections are leaking
I don't understand what you mean by "idle connections". Could you detail this more, please? Where are this connections, which code did you run to create them, and where are you seeing them could be a nice start.
Simple select with join(WithXXX)
it's called idle in connection issue. So, postgres executes the query, and then waiting for the client to read data.
But it doesn't, so it opens a new connection, which also executes the query and doesn't read data from it.
Maybe, this issue happens when we are using cross compilation
See https://github.com/src-d/go-kallax/blob/master/generator/templates/model.tgo#L438
It seems to leak db connection.
defer rs.Close()
is expected in that function.
@qJkee want to describe this problem?
I guess, this issue's title to be "Generated FindAll() function leaks database connections".
Done!
Yes, it's leaking connection, because after restarting app, all connections closing
I'm marking this as a confirmed bug then.
This still needs some investigation to see where the connection should be closed. I'll take a look into it as soon as I get back from vacation.
I definitely found leaking point, Reload() is.
I send a pull-request to check connection was leaked or not in each test.
@qJkee Really sorry, Im wrong. Can you check your code that uses Reload() or not.
You can avoid this problem by removing Reload() in your code if you used, maybe.
@roobre review my pr, please.