Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRPC Tcc 下 try 出现异常不会执行 cancel 而是直接成功 #32

Open
kids-return opened this issue Aug 12, 2022 · 4 comments
Open

Comments

@kids-return
Copy link
Contributor

TCC callBranch 会通过 transRequestBranch 发起请求
最后会 通过 invoke 执行到 _simpleRequest
_simpleRequest 里服务端出错客户端不会抛出异常

GrpcApi transRequestBranch

    public function transRequestBranch(RequestBranch $requestBranch)
    {
        [$hostname, $method] = $this->parseHostnameAndMethod($requestBranch->url);
        $client = $this->grpcClientManager->getClient($hostname);
        $response = $client->invoke($method, $requestBranch->grpcArgument, $requestBranch->grpcDeserialize, $requestBranch->grpcMetadata, $requestBranch->grpcOptions);
        dump($response);
    }

TCC globalTransaction

    public function globalTransaction(callable $callback, ?string $gid = null)
    {
        $this->init($gid);
        $requestBody = TransContext::toArray();
        try {
            $this->api->prepare($requestBody);
            $callback($this);
        } catch (\Throwable $throwable) {
            $this->api->abort($requestBody);
            throw $throwable;
        }

        $this->api->submit($requestBody);
    }

globalTransaction 的 callback 执行 _simpleRequest,即使服务端出现异常客户端也不会抛出来,所以catch 里永远不会捕获到异常
导致 abort 永远不会执行,最终会走到 submit

@kids-return
Copy link
Contributor Author

建议 gRPC 客户端可以配置,进行自定义处理。

@kids-return
Copy link
Contributor Author

我目前的 gRPC 客户端是复制了 hyperf 的进行自定义处理定制的。可能要通过 class_map 来进行自定义的替换 DTM 的 gRPC 客户端

@kids-return
Copy link
Contributor Author

hyperf/hyperf#5013 这个 PR 希望可以通过,进行继承扩展。因为有些 private 的方法导致只能复制,个人维护起来也麻烦

@kids-return
Copy link
Contributor Author

我目前自定义的客户端,使用了统一的异常,Server 抛出的异常客户端也会转换为相应的异常,我的方案对于我可行,不确定 hyperf 的 gRPC 是否愿意接受相关的 PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant