Skip to content

Commit 062fefe

Browse files
authored
Avoid a panic when using transaction (#1144)
### Motivation When aborting or committing a transaction, it can happen that an error returned from the client triggers a panic when attempting to cast it to a Pulsar error. ### Modifications A proper check is performed when casting the error.
1 parent bd11581 commit 062fefe

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pulsar/transaction_impl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (txn *transaction) Commit(ctx context.Context) error {
101101
if err == nil {
102102
atomic.StoreInt32((*int32)(&txn.state), int32(TxnCommitted))
103103
} else {
104-
if err.(*Error).Result() == TransactionNoFoundError || err.(*Error).Result() == InvalidStatus {
104+
if e, ok := err.(*Error); ok && (e.Result() == TransactionNoFoundError || e.Result() == InvalidStatus) {
105105
atomic.StoreInt32((*int32)(&txn.state), int32(TxnError))
106106
return err
107107
}
@@ -127,7 +127,7 @@ func (txn *transaction) Abort(ctx context.Context) error {
127127
if err == nil {
128128
atomic.StoreInt32((*int32)(&txn.state), int32(TxnAborted))
129129
} else {
130-
if err.(*Error).Result() == TransactionNoFoundError || err.(*Error).Result() == InvalidStatus {
130+
if e, ok := err.(*Error); ok && (e.Result() == TransactionNoFoundError || e.Result() == InvalidStatus) {
131131
atomic.StoreInt32((*int32)(&txn.state), int32(TxnError))
132132
} else {
133133
txn.opsFlow <- true

0 commit comments

Comments
 (0)