This is an automated email from the ASF dual-hosted git repository.
zike pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git
The following commit(s) were added to refs/heads/master by this push:
new 062fefe1 Avoid a panic when using transaction (#1144)
062fefe1 is described below
commit 062fefe12be229617b1f7e499969355c02470793
Author: Gaylor Bosson <[email protected]>
AuthorDate: Tue Dec 19 11:17:47 2023 +0100
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.
---
pulsar/transaction_impl.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pulsar/transaction_impl.go b/pulsar/transaction_impl.go
index 8a24c464..2eb8aca9 100644
--- a/pulsar/transaction_impl.go
+++ b/pulsar/transaction_impl.go
@@ -101,7 +101,7 @@ func (txn *transaction) Commit(ctx context.Context) error {
if err == nil {
atomic.StoreInt32((*int32)(&txn.state), int32(TxnCommitted))
} else {
- if err.(*Error).Result() == TransactionNoFoundError ||
err.(*Error).Result() == InvalidStatus {
+ if e, ok := err.(*Error); ok && (e.Result() ==
TransactionNoFoundError || e.Result() == InvalidStatus) {
atomic.StoreInt32((*int32)(&txn.state), int32(TxnError))
return err
}
@@ -127,7 +127,7 @@ func (txn *transaction) Abort(ctx context.Context) error {
if err == nil {
atomic.StoreInt32((*int32)(&txn.state), int32(TxnAborted))
} else {
- if err.(*Error).Result() == TransactionNoFoundError ||
err.(*Error).Result() == InvalidStatus {
+ if e, ok := err.(*Error); ok && (e.Result() ==
TransactionNoFoundError || e.Result() == InvalidStatus) {
atomic.StoreInt32((*int32)(&txn.state), int32(TxnError))
} else {
txn.opsFlow <- true