报错问题
2023/010/28 17:20:10.250768 default_server_handler.go:234: [Error] KITEX: processing request error, remoteService=, remoteAddr=127.0.0.1:65425, error=default codec read failed: read tcp 127.0.0.1:8888->127.0.0.1:65425: i/o timeout
分析原因
Hertz rpc 调用base-service服务,kitex不设置读写超时时间默认5s,既在5s内没有收到请求就超时,导致后面请求无法接收,所以只需要设置超时控制时间即可
解决方案
原因:kitex超时控制
详细请见cloudwego文档:https://www.cloudwego.io/zh/docs/kitex/tutorials/service-governance/timeout/
```
package main
import (
"github.com/cloudwego/kitex/server"
"go.uber.org/zap"
"log"
"net"
"qiniu/cmd/social/db"
example "qiniu/cmd/social/kitex_gen/social/example/socialservice"
"time"
)
func main() {
addr, _ := net.ResolveTCPAddr("tcp", ":8801")
var opts []server.Option
//配置超时控制
opts = append(opts, server.WithServiceAddr(addr))
opts = append(opts, server.WithReadWriteTimeout(365*24*60*60*time.Second))
opts = append(opts, server.WithExitWaitTime(365*24*60*60*time.Second))
svr := example.NewServer(new(SocialServiceImpl), opts...)
db.Init()
logger, _ := zap.NewDevelopment()
zap.ReplaceGlobals(logger)
err := svr.Run()
if err != nil {
log.Println(err.Error())
}
}