From 69026e85321f1ca2443fbcb8bbff8293ecd4d06e Mon Sep 17 00:00:00 2001 From: AlexStocks <alexstocks@foxmail.com> Date: Sun, 3 Jan 2021 02:50:33 +0800 Subject: [PATCH] fix protocol linter error --- protocol/dubbo/hessian2/hessian_request.go | 20 ++++++++++++++++---- protocol/jsonrpc/http.go | 8 +++++--- protocol/jsonrpc/server.go | 8 ++++++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/protocol/dubbo/hessian2/hessian_request.go b/protocol/dubbo/hessian2/hessian_request.go index 4ebb4aa1b..2a1d5f736 100644 --- a/protocol/dubbo/hessian2/hessian_request.go +++ b/protocol/dubbo/hessian2/hessian_request.go @@ -30,6 +30,10 @@ import ( perrors "github.com/pkg/errors" ) +import ( + "github.com/apache/dubbo-go/common/logger" +) + ///////////////////////////////////////// // dubbo ///////////////////////////////////////// @@ -221,10 +225,18 @@ func packRequest(service Service, header DubboHeader, req interface{}) ([]byte, } // dubbo version + path + version + method - encoder.Encode(DEFAULT_DUBBO_PROTOCOL_VERSION) - encoder.Encode(service.Path) - encoder.Encode(service.Version) - encoder.Encode(service.Method) + if err := encoder.Encode(DEFAULT_DUBBO_PROTOCOL_VERSION); err != nil { + logger.Error("Encode(DEFAULT_DUBBO_PROTOCOL_VERSION) = error: %v", err) + } + if err := encoder.Encode(service.Path); err != nil { + logger.Error("Encode(service.Path) = error: %v", err) + } + if err := encoder.Encode(service.Version); err != nil { + logger.Error("Encode(service.Version) = error: %v", err) + } + if err := encoder.Encode(service.Method); err != nil { + logger.Error("Encode(service.Method) = error: %v", err) + } // args = args type list + args value list if types, err = getArgsTypeList(args); err != nil { diff --git a/protocol/jsonrpc/http.go b/protocol/jsonrpc/http.go index 869617ea4..7ab1a8942 100644 --- a/protocol/jsonrpc/http.go +++ b/protocol/jsonrpc/http.go @@ -181,15 +181,17 @@ func (c *HTTPClient) Do(addr, path string, httpHeader http.Header, body []byte) return nil, perrors.WithStack(err) } defer tcpConn.Close() - setNetConnTimeout := func(conn net.Conn, timeout time.Duration) { + setNetConnTimeout := func(conn net.Conn, timeout time.Duration) error { t := time.Time{} if timeout > time.Duration(0) { t = time.Now().Add(timeout) } - conn.SetDeadline(t) + return conn.SetDeadline(t) + } + if err := setNetConnTimeout(tcpConn, c.options.HTTPTimeout); err != nil { + return nil, err } - setNetConnTimeout(tcpConn, c.options.HTTPTimeout) if _, err = reqBuf.WriteTo(tcpConn); err != nil { return nil, perrors.WithStack(err) diff --git a/protocol/jsonrpc/server.go b/protocol/jsonrpc/server.go index 755aa7da7..76901bff6 100644 --- a/protocol/jsonrpc/server.go +++ b/protocol/jsonrpc/server.go @@ -92,7 +92,9 @@ func (s *Server) handlePkg(conn net.Conn) { t = time.Now().Add(timeout) } - conn.SetDeadline(t) + if err := conn.SetDeadline(t); err != nil { + logger.Error("connection.SetDeadline(t:%v) = error:%v", t, err) + } } sendErrorResp := func(header http.Header, body []byte) error { @@ -239,7 +241,9 @@ func (s *Server) Start(url *common.URL) { s.wg.Add(1) go func() { - accept(listener, func(conn net.Conn) { s.handlePkg(conn) }) + if err := accept(listener, func(conn net.Conn) { s.handlePkg(conn) }); err != nil { + logger.Error("accept() = error:%v", err) + } s.wg.Done() }() -- GitLab