如何处理sql.ErrTxDone

I am for example trying to create a new record in my mysql database. In the case of a sql.ErrTxDone, what does it actually mean, what should i do in-case the transaction was committed ?

You get this error if a transaction is in a state where it cannot be used anymore.

sql.Tx:

After a call to Commit or Rollback, all operations on the transaction fail with ErrTxDone.

And also sql.ErrTxDone:

ErrTxDone is returned by any operation that is performed on a transaction that has already been committed or rolled back.

var ErrTxDone = errors.New("sql: transaction has already been committed or rolled back")

What should you do? Don't use the transaction anymore. If you have further task, do it outside of it or in another transaction.

If you have tasks that should be in the same transaction, don't commit it until you do everything you have to. If the transaction was rolled back (e.g. due to a previous error), you have no choice but to retry (using another transaction) or report failure.

If you're already using transactions, try to put everything in the transaction that needs to happen all-or-nothing. That's the point of transactions. Either everything in it gets applied, or none of them. Using them properly you don't have to think about cleaning up after them. They either succeed and you're happy, or they don't and you either retry or report error, but you don't have to do any cleanup.