For CockroachDB, a certain error code (40001) is returned, which signals to the caller that there is a retryable transaction error. The client is then expected to retry, just like some answers above indicate.
Docs here: https://www.cockroachlabs.com/docs/stable/common-errors#restart-transaction