Skip to content

Commit 2bc29e6

Browse files
authored
Merge pull request #735 from twmb/example-messup
eos example: avoid short-circuit logic
2 parents c77d58e + 0574d20 commit 2bc29e6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

examples/transactions/eos/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ func inputProducer() {
7575
for i := 0; i < 10; i++ {
7676
cl.Produce(ctx, kgo.StringRecord(msg+strconv.Itoa(i)), e.Promise())
7777
}
78-
commit := kgo.TransactionEndTry(doCommit && e.Err() == nil)
78+
perr := e.Err() // always evaluate e.Err() to ensure we do not short circuit in the logic below (doCommit && ... would fail if doCommit is false!)
79+
commit := kgo.TransactionEndTry(doCommit && perr == nil)
7980

8081
switch err := cl.EndTransaction(ctx, commit); err {
8182
case nil:

0 commit comments

Comments
 (0)