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

Client 复用同个连接,出现 rpc error: code = Unknown desc = #8

Open
eddycjy opened this issue Apr 18, 2019 · 3 comments
Open

Comments

@eddycjy
Copy link

eddycjy commented Apr 18, 2019

问题

客户端复用 ClientConn 后,无法再次调用 RPC 方法成功

server

直接使用 greeter_server.php

client

直接改造 greeter_client.go,如下:

package main

import (
	"log"
	"os"

	"golang.org/x/net/context"
	"google.golang.org/grpc"
	pb "google.golang.org/grpc/examples/helloworld/helloworld"
)

const (
	address     = "localhost:50051"
	defaultName = "world"
)

func main() {
	// Set up a connection to the server.
	conn, err := grpc.Dial(address, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	defer conn.Close()
	c := pb.NewGreeterClient(conn)

	// Contact the server and print out its response.
	name := defaultName
	if len(os.Args) > 1 {
		name = os.Args[1]
	}
	r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: name})
	if err != nil {
		log.Fatalf("could not greet1: %v", err)
	}
	log.Printf("Greeting: %s", r.Message)

	r, err = c.SayHello(context.Background(), &pb.HelloRequest{Name: name})
	if err != nil {
		log.Fatalf("could not greet2: %v", err)
	}
	log.Printf("Greeting: %s", r.Message)
}

输出结果

$ go run greeter_client.go
2019/04/18 14:18:06 Greeting: Hello world
2019/04/18 14:18:06 could not greet2: rpc error: code = Unknown desc = 
exit status 1
@eddycjy eddycjy changed the title 复用同个连接,出现 rpc error: code = Unknown desc = Client 复用同个连接,出现 rpc error: code = Unknown desc = Apr 18, 2019
@eddycjy
Copy link
Author

eddycjy commented Apr 18, 2019

PHP 版本

$ php -v
PHP 7.2.11 (cli) (built: Oct 21 2018 18:28:44) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.11, Copyright (c) 1999-2018, by Zend Technologies

Swoole 版本

$ php --ri swoole

swoole

swoole support => enabled
Version => 4.2.3
Author => Swoole Group[email: [email protected]]
coroutine => enabled
kqueue => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.0.2p  14 Aug 2018
http2 => 1.34.0
pcre => enabled
zlib => enabled
brotli => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.use_namespace => On => On
swoole.use_shortname => On => On
swoole.fast_serialize => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608

Go 版本

$ go version
go version go1.11.5 darwin/amd64

@mmaxiaolei
Copy link

@eddycjy 请问这个问题有解决吗?麻烦分享一下解决方法

@zewenying
Copy link

可以试下在client端和server端增加以下配置:
ClientParameters.PermitWithoutStream=true
EnforcementPolicy. PermitWithoutStream=true
参考链接:https://godoc.org/google.golang.org/grpc/keepalive

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

No branches or pull requests

4 participants