XiaoFeiASK commented on code in PR #1160:
URL: 
https://github.com/apache/incubator-seata-go/pull/1160#discussion_r3924027587


##########
pkg/tm/transaction/endphase/endphase.go:
##########
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Package endphase normalizes the outcome of a global transaction second
+// phase so that every transport classifies the same situation the same way.
+package endphase
+
+import (
+       "context"
+       "errors"
+       "fmt"
+)
+
+// ErrEmptyResponse reports a second phase that finished without a transport
+// error but produced no response for the caller to read a status from.
+var ErrEmptyResponse = errors.New("empty second phase response")
+
+// Err turns the outcome of a commit or rollback retry loop into a single error
+// value, and returns nil only when res holds a response the caller can use.
+//
+// The retry loops stop as soon as the backoff is no longer Ongoing, which also
+// happens when the caller's context is already done before the first attempt.
+// No request is sent in that case and sendErr stays nil, so callers must never
+// treat a nil sendErr on its own as success.
+//
+// Checks run in a fixed order:
+//
+//  1. a response that came back, which outranks everything else
+//  2. the caller's context, so a canceled or expired context is reported as
+//     such and stays matchable with errors.Is
+//  3. the last transport error, annotated with why the retries stopped
+//  4. the backoff terminating on its own, that is, retries exhausted
+//  5. a missing response
+func Err(ctx context.Context, sendErr, backoffErr error, res interface{}) 
error {
+       // A response outranks a done context. The transports send without a
+       // context, so the retry loop can outlive the deadline while the request
+       // itself still reached the TC and came back. Reporting a failure here
+       // would hide a second phase that actually completed.
+       if sendErr == nil && res != nil {

Review Comment:
   这里仅通过 res != nil 判断二阶段请求成功,但 Getty 的空响应或损坏响应可能会被解码成非 nil 的零值 
message.Global*Response,其 GlobalStatus 为 GlobalStatusUnKnown。这样会导致 
Commit/Rollback 返回 nil,并将无效响应当成成功处理。建议在 Getty 侧校验响应状态,或增加对零值响应的判断。



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to