Skip to content

initializing client.Batch outside of txn retryable is dangerous #3067

@tbg

Description

@tbg

This here will go horribly wrong (endless retry loop) unless the retryable succeeds on its first attempt.

b := &client.Batch{}
b.Put(key, "test")

s.db.Txn(func(txn *client.Txn) error {
        return txn.CommitInBatch(b)
})

Instead, the batch needs to be initialized inside of the retryable (or the error stored within it cleared manually). I ran into this in WIP and took me a bit to track it down. We should reset errors in an appropriate location so that the above isn't a death trap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyEasy issue to tackle, requires little or no CockroachDB experiencehelp wantedHelp is requested / needed by the one who filed the issue to fix it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions