Prevent retrying on slow transactions

When using the Go bindings, is there a way to prevent Transact from retrying when the transaction fails due to taking more than 5 seconds (FoundationDB error code 1007 (Transaction is too old to perform reads or be committed)? For example, this code will just keep on retrying forever:

	_, err := db.Transact(func(tr fdb.Transaction) (interface{}, error) {
		tr.Get(fdb.Key("foo")).MustGet()

		// Simulate slow transaction
		time.Sleep(6 * time.Second)

		tr.Set(fdb.Key("bar"), []byte{1})

		return nil, nil
	})

You can configure the retry behavior by setting a retry limit or timeout on the transaction or as a database default.

With a retry limit, the transaction will fail with the last error if it wants to retry but has met the limit. With a timeout, you will get a timeout error if the transaction takes longer than the specified duration.

1 Like