CockroachDB has a serializable isolation level, so it may be necessary to break up statements into multiple transactions or have the application retry operations. See: https://www.cockroachlabs.com/docs/stable/transaction-retry-error-reference.html#retry_serializable, which describes how applications should handle these errors.
Cockroach internally at the server side will also retry your transaction if possible, for example, if no result sets are returned to the client. But it may not be possible in all cases, and some design considerations have to be taken on the application side