Description
If you use the current batch API, it's possible some connections aren't being closed correctly. This can happen if you return early due to an err
elsewhere in between PrepareBatch
and Send
. It can be somewhat safely handled with batch.Abort()
, but this doesn't always cleanly cancel the insert.
I intend on adding a batch.Close()
function to the batch interface to verify the connection is cleaned up and returned to the pool, while also verifying the insert is closed safely on the server side.
It would look something like this:
batch, err := conn.PrepareBatch(ctx, "INSERT INTO function null('x UInt64') VALUES (1)")
// This defer call will make sure the batch is absolutely cleaned up before it falls out of scope.
// This function does not exist yet, we need to add it to our driver code.
defer batch.Close()
With this defer
call, it would verify that the batch is absolutely contained to the scope and the connection does not stay alive longer than it needs to be.
This doesn't cause a panic or data loss, but it does waste a connection on the server. Eventually the client or server will timeout the connection, but we don't want to waste resources waiting for this to happen. It also leaves an error in system.query_log
.
Code will need to be updated to include defer batch.Close()