Skip to content

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

@kids-return

Description

@kids-return

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions