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

rpcx sendraw response Error #371

Closed
bbqbyte opened this issue Oct 14, 2019 · 9 comments
Closed

rpcx sendraw response Error #371

bbqbyte opened this issue Oct 14, 2019 · 9 comments
Assignees

Comments

@bbqbyte
Copy link

bbqbyte commented Oct 14, 2019

env: go 1.12.1
rpcx: github.com/smallnest/rpcx v0.0.0-20191008054500-6a4c1b1de0fa
使用client.sendraw, SerializeType:protobuf
响应的PB格式:
import "google/protobuf/any.proto";
// response
message Resp {
int32 code = 1; // 返回码
uint64 req_time = 2; // 请求时间
uint64 time = 3; // 当前服务器时间
string msg = 4;
google.protobuf.Any data = 5;
}


使用:
go funcA() { client.Sendraw(....) }()
go funcB() { client.Sendraw(....) }()
同时请求同一个servicepath和servicemethod,偶尔出现sendraw响应的payload错误(貌似内存被覆盖)。
在client/client.go 的input接收数据时:
if call.Raw {
call.Metadata, call.Reply, _ = convertRes2Raw(res)
log.Info("call payload: ", call.Reply, "args=", call.Args)
} 这里的call.Reply的内容是正确的,然后进入call.done(),将call对象发给call内部的channel,
在channel接收数据后
select {
.....
case call := <-done:
err = call.Error
m = call.Metadata
if call.Reply != nil {
// 这里的call.Reply的数据(protobuf的marshal)偶尔出现问题,和上面client.input时接收的不一致
log.Info("chan payload: ", call.Reply, "args=", call.Args)
payload = call.Reply.([]byte)
}
}
}

求大神指导下

@bbqbyte
Copy link
Author

bbqbyte commented Oct 14, 2019

以下是出现问题的 log call payload: 和 chan payload: 打印
2019/10/14 06:50:14.807 [RPCX.rpc] [I] call payload: [16 131 183 160 200 220 45 24 166 181 144 237 5 42 8 18 6 16 166 181 144 237 5] seq=18
2019/10/14 06:50:14.807 [RPCX.rpc] [I] call payload: [16 130 183 160 200 220 45 24 166 181 144 237 5 42 0] seq=17
2019/10/14 06:50:14.808 [Proxy.node] [E] bug: payload error="proto: wrong wireType = 2 for field ReqTime" serialtype=2
2019/10/14 06:50:14.808 [RPCX.rpc] [I] chan payload: [16 130 183 160 200 220 45 24 166 181 144 237 5 42 0 18 6 16 166 181 144 237 5] seq=18
2019/10/14 06:50:14.808 [RPCX.rpc] [I] chan payload: [16 130 183 160 200 220 45 24 166 181 144 237 5 42 0] seq=17

@smallnest smallnest self-assigned this Oct 14, 2019
@smallnest
Copy link
Owner

你的rpcx的版本?

@bbqbyte
Copy link
Author

bbqbyte commented Oct 14, 2019

go mod github.com/smallnest/rpcx v0.0.0-20191008054500-6a4c1b1de0fa

@bbqbyte
Copy link
Author

bbqbyte commented Oct 14, 2019

func TestSS(t *testing.T) {
	rep := getTicketLocal_test()
	if rep.Ticket == nil {
		panic("ticket invalid")
	}

	wg1.Add(2)
	nowt := utils.TimestampUint()

	option := client.DefaultOption
	option.SerializeType = protocol.ProtoBuffer
	
	d := client.NewEtcdDiscovery("/com/keywea/rpcx", "com.keywea.PlayerService", []string{"localhost:2379"}, nil)
	xclient := client.NewXClient("com.keywea.PlayerService", client.Failfast, client.RandomSelect, d, option)
	defer xclient.Close()

	args := &res.Resq{
		Ticket:  rep.Ticket,
		ReqTime: nowt,
		Biz:     3020,
	}
	d1, _ := args.Marshal()
	go request(xclient, 1, d1)

	args2 := &res.Resq{
		Ticket:  rep.Ticket,
		ReqTime: nowt,
		Biz:     3023,
	}
	d2, _ := args2.Marshal()
	go request(xclient, 2, d2)

	wg1.Wait()
}

@bbqbyte
Copy link
Author

bbqbyte commented Oct 14, 2019

func request(c client.XClient, seqid uint64, body []byte) {
	rpcxReq := protocol.GetPooledMsg()
	rpcxReq.SetMessageType(protocol.Request)
	rpcxReq.SetSeq(seqid)
	rpcxReq.ServicePath = "com.keywea.PlayerService"
	rpcxReq.ServiceMethod = "Bizz"
	rpcxReq.SetSerializeType(protocol.ProtoBuffer)
	rpcxReq.Payload = body
	rpcxReq.SetOneway(false)
	defer protocol.FreeMsg(rpcxReq)

	rpcctx, cancelFn := context.WithTimeout(context.Background(), time.Duration(10*time.Second))
	_, payload, e := c.SendRaw(rpcctx, rpcxReq)
	cancelFn()
	if e != nil {
		fmt.Println(e)
	}

	fmt.Println("bug: playload len", len(payload))
	respp := &res.Resp{}
	epp := respp.Unmarshal(payload)
	if epp != nil {
		fmt.Println("bug: payload", epp)
	}
	wg1.Done()
}

@bbqbyte
Copy link
Author

bbqbyte commented Oct 14, 2019

=== RUN   TestSS
2019/10/14 16:07:42 client.go:626: INFO : call payload: [16 206 217 144 237 5 24 206 217 144 237 5 42 8 18 6 16 206 217 144 237 5]args=2
2019/10/14 16:07:42 client.go:626: INFO : call payload: [16 206 217 144 237 5 24 206 217 144 237 5 42 0]args=1
2019/10/14 16:07:42 client.go:419: INFO : chan payload: [16 206 217 144 237 5 24 206 217 144 237 5 42 0]args=1
bug: playload len 14
2019/10/14 16:07:42 client.go:419: INFO : chan payload: [16 206 217 144 237 5 24 206 217 144 237 5 42 0 18 6 16 206 217 144 237 5]args=2
bug: playload len 22
bug: payload proto: wrong wireType = 2 for field ReqTime
--- PASS: TestSS (0.04s)

@smallnest
Copy link
Owner

fixed, 你拉取一下代码试试

@bbqbyte
Copy link
Author

bbqbyte commented Oct 14, 2019

fixed, 你拉取一下代码试试

好,谢谢大神

@JungleYe
Copy link

JungleYe commented May 6, 2020

留记号:看来平常应该关注这里的bug fix;

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

3 participants