minus5/gofreetds

pool.Get() does not return

Closed this issue · 2 comments

We encountered a rare situation where a pool.Get() did not return.
This could be because of earlier connections were not released.
That could be because of hung queries.

So, because the pool.Get() did not return (blocked on p.poolGuard <- true , conn_pool.go:103), the operations timed out without errors.

A timeout logic or context is needed so that if getting a connection is hung, some kind of timeout brings the control back.

Not really much to go on here....
If as you said blocked on:

p.poolGuard <- true //make reservation, blocks if poolGuard is full

You have spent all connections in pool and you can't add new...

Even by adding timeout or context there is no real guarantee that connection with valid long running operation wouldn't be killed just because implied timeout.

So instead I would suggest check SQL server side what is really causing your operations not to finish.
Also I can suggest to check your connect string and parameter max_pool_size if you need more connections in pool to execute more concurrent operations.

//Max number of connections in the pool is controlled by max_pool_size connection string parameter, default is 100.

If you experience blocks from time to time it is worth checking do you really need larger connection pool.

But if you have hung queries that eventually eat complete pool, this is best place to focus on and see what is really going on.
Until you resolve that issue no timeout or context would help you maybe it would even make real issue harder to track and fix.

Correct,
for our application logic, this causes problem,
so, I was thinking of adding additional functions like GetWithContext()
so that application could take some action,
while those who would not need it would keep using Get()