database/sql: fix transaction leak
database/sql: fix transaction leak

When the user context which passed in (*DB)BeginTx is canceled or
timeout, the current implementation could cause db transaction leak
in some extreme scenario.

Goroutine 1:
        Call (*DB) BeginTx begins a transaction with a userContext.
        In (*DB)BeginTx, a new goroutine (*Tx)awaitDone
        which monitor context and rollback tx if needed will be created

Goroutine 2(awaitDone):
        block on tx.ctx.Done()

Goroutine 1:
        Execute some insert or update sqls on the database

Goroutine 1:
        Commit the transaction, (*Tx)Commit set
        the atomic variable tx.done to 1

Goroutine 3(maybe global timer):
        Cancel userContext which be passed in Tx

Goroutine 1:
        (*Tx)Commit checks tx.ctx.Done().
        Due to the context has been canceled, it will return
        context.Canceled or context.DeadlineExceeded error immediately
        and abort the real COMMIT operation of transaction

Goroutine 2:
        Release with tx.ctx.Done() signal, execute (*Tx)rollback.
        However the atomic variable tx.done is 1 currently,
        it will return ErrTxDone error immediately and
        abort the real ROLLBACK operation of transaction

Fixes #22976

Change-Id: I3bc23adf25db823861d91e33d3cca6189fb1171d
Reviewed-on: https://go-review.googlesource.com/81736
Run-TryBot: Brad Fitzpatrick <ae9783c0b0efc69cd85ab025ddd17aa44cdc4aa5@golang.org>
Reviewed-by: Daniel Theophanes <14db39248b80c6688f7e9808ba5055f2e56426f3@gmail.com>

josharian/go,golang/go,Cofyc/go,Cofyc/go,codestation/go,cloudflare/go,nawawi/go,josharian/go,cloudflare/go,Cofyc/go,akutz/go,CAFxX/go,CAFxX/go,cloudflare/go,josharian/go,josharian/go,codestation/go,CAFxX/go,nawawi/go,golang/go,cloudflare/go,cloudflare/go,nawawi/go,cloudflare/go,akutz/go,Cofyc/go,akutz/go,akutz/go,CAFxX/go,golang/go,golang/go,josharian/go,nawawi/go,nawawi/go,akutz/go,akutz/go,nawawi/go,CAFxX/go,codestation/go,codestation/go,codestation/go,golang/go,akutz/go,nawawi/go,codestation/go,codestation/go,Cofyc/go,CAFxX/go,josharian/go,christopher-henderson/Go,cloudflare/go,golang/go,Cofyc/go,golang/go,josharian/go,CAFxX/go,Cofyc/go,cloudflare/go,akutz/go,josharian/go,Cofyc/go,nawawi/go,codestation/go,golang/go,CAFxX/go