This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/3.0 by this push:
new bd9806c9c fix: limit rpc package data size by user's config rather
than DEFAULT_LEN. (#1848)
bd9806c9c is described below
commit bd9806c9cb3accb894c36b2050259112e5f1762b
Author: Stonex <[email protected]>
AuthorDate: Sun May 8 12:34:12 2022 +0800
fix: limit rpc package data size by user's config rather than DEFAULT_LEN.
(#1848)
* fix: limit rpc package data size by user's config rather than DEFAULT_LEN
* Dubbo recommand package data length not greater than 8MiB.
* If package data length greater than 8MiB, generate warnning.
* If package data lenght greater than user's config, generate exception.
Signed-off-by: stonex <[email protected]>
* fix: fix warning when package size greater than 8MiB
---
protocol/dubbo/hessian2/hessian_request.go | 5 +++--
protocol/dubbo/hessian2/hessian_response.go | 5 +++--
protocol/dubbo/impl/codec.go | 10 ++++++----
remoting/getty/readwriter.go | 23 +++++++++++++++++++++++
4 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/protocol/dubbo/hessian2/hessian_request.go
b/protocol/dubbo/hessian2/hessian_request.go
index 1a92b6661..11c407a25 100644
--- a/protocol/dubbo/hessian2/hessian_request.go
+++ b/protocol/dubbo/hessian2/hessian_request.go
@@ -172,8 +172,9 @@ func packRequest(service Service, header DubboHeader, req
interface{}) ([]byte,
END:
byteArray = encoder.Buffer()
pkgLen = len(byteArray)
- if pkgLen > int(DEFAULT_LEN) { // 8M
- return nil, perrors.Errorf("Data length %d too large, max
payload %d", pkgLen, DEFAULT_LEN)
+ if pkgLen > int(DEFAULT_LEN) { // recommand 8M
+ logger.Warnf("Data length %d too large, recommand max payload
%d. "+
+ "Dubbo java can't handle the package whose size is
greater than %d!!!", pkgLen, DEFAULT_LEN, DEFAULT_LEN)
}
// byteArray{body length}
binary.BigEndian.PutUint32(byteArray[12:], uint32(pkgLen-HEADER_LENGTH))
diff --git a/protocol/dubbo/hessian2/hessian_response.go
b/protocol/dubbo/hessian2/hessian_response.go
index 157219735..51bc72580 100644
--- a/protocol/dubbo/hessian2/hessian_response.go
+++ b/protocol/dubbo/hessian2/hessian_response.go
@@ -164,8 +164,9 @@ func packResponse(header DubboHeader, ret interface{})
([]byte, error) {
byteArray = encoder.Buffer()
byteArray = hessian.EncNull(byteArray) // if not, "java client" will
throw exception "unexpected end of file"
pkgLen := len(byteArray)
- if pkgLen > int(DEFAULT_LEN) { // 8M
- return nil, perrors.Errorf("Data length %d too large, max
payload %d", pkgLen, DEFAULT_LEN)
+ if pkgLen > int(DEFAULT_LEN) { // recommand 8M
+ logger.Warnf("Data length %d too large, recommand max payload
%d. "+
+ "Dubbo java can't handle the package whose size greater
than %d!!!", pkgLen, DEFAULT_LEN, DEFAULT_LEN)
}
// byteArray{body length}
binary.BigEndian.PutUint32(byteArray[12:], uint32(pkgLen-HEADER_LENGTH))
diff --git a/protocol/dubbo/impl/codec.go b/protocol/dubbo/impl/codec.go
index 95acbd9e0..46e8dadba 100644
--- a/protocol/dubbo/impl/codec.go
+++ b/protocol/dubbo/impl/codec.go
@@ -232,8 +232,9 @@ func packRequest(p DubboPackage, serializer Serializer)
([]byte, error) {
return nil, err
}
pkgLen = len(body)
- if pkgLen > int(DEFAULT_LEN) { // 8M
- return nil, perrors.Errorf("Data length %d too large,
max payload %d", pkgLen, DEFAULT_LEN)
+ if pkgLen > int(DEFAULT_LEN) { // recommand 8M
+ logger.Warnf("Data length %d too large, recommand max
payload %d. "+
+ "Dubbo java can't handle the package whose size
is greater than %d!!!", pkgLen, DEFAULT_LEN, DEFAULT_LEN)
}
byteArray = append(byteArray, body...)
}
@@ -269,8 +270,9 @@ func packResponse(p DubboPackage, serializer Serializer)
([]byte, error) {
}
pkgLen := len(body)
- if pkgLen > int(DEFAULT_LEN) { // 8M
- return nil, perrors.Errorf("Data length %d too large, max
payload %d", pkgLen, DEFAULT_LEN)
+ if pkgLen > int(DEFAULT_LEN) { // recommand 8M
+ logger.Warnf("Data length %d too large, recommand max payload
%d. "+
+ "Dubbo java can't handle the package whose size is
greater than %d!!!", pkgLen, DEFAULT_LEN, DEFAULT_LEN)
}
// byteArray{body length}
binary.BigEndian.PutUint32(byteArray[12:], uint32(pkgLen))
diff --git a/remoting/getty/readwriter.go b/remoting/getty/readwriter.go
index 18904dc36..b3956e171 100644
--- a/remoting/getty/readwriter.go
+++ b/remoting/getty/readwriter.go
@@ -29,6 +29,7 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/common/logger"
+ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo/impl"
"dubbo.apache.org/dubbo-go/v3/remoting"
)
@@ -61,8 +62,14 @@ func (p *RpcClientPackageHandler) Read(ss getty.Session,
data []byte) (interface
// Write send the data to server
func (p *RpcClientPackageHandler) Write(ss getty.Session, pkg interface{})
([]byte, error) {
req, ok := pkg.(*remoting.Request)
+ maxBufLength := clientConf.GettySessionParam.MaxMsgLen +
impl.HEADER_LENGTH
if ok {
buf, err := (p.client.codec).EncodeRequest(req)
+ bufLength := buf.Len()
+ if bufLength > maxBufLength {
+ logger.Errorf("Data length %d too large, max payload
%d", bufLength-impl.HEADER_LENGTH, clientConf.GettySessionParam.MaxMsgLen)
+ return nil, perrors.Errorf("Data length %d too large,
max payload %d", bufLength-impl.HEADER_LENGTH,
clientConf.GettySessionParam.MaxMsgLen)
+ }
if err != nil {
logger.Warnf("binary.Write(req{%#v}) = err{%#v}", req,
perrors.WithStack(err))
return nil, perrors.WithStack(err)
@@ -73,6 +80,11 @@ func (p *RpcClientPackageHandler) Write(ss getty.Session,
pkg interface{}) ([]by
res, ok := pkg.(*remoting.Response)
if ok {
buf, err := (p.client.codec).EncodeResponse(res)
+ bufLength := buf.Len()
+ if bufLength > maxBufLength {
+ logger.Errorf("Data length %d too large, max payload
%d", bufLength-impl.HEADER_LENGTH, clientConf.GettySessionParam.MaxMsgLen)
+ return nil, perrors.Errorf("Data length %d too large,
max payload %d", bufLength-impl.HEADER_LENGTH,
clientConf.GettySessionParam.MaxMsgLen)
+ }
if err != nil {
logger.Warnf("binary.Write(res{%#v}) = err{%#v}", req,
perrors.WithStack(err))
return nil, perrors.WithStack(err)
@@ -112,8 +124,14 @@ func (p *RpcServerPackageHandler) Read(ss getty.Session,
data []byte) (interface
// Write send the data to client
func (p *RpcServerPackageHandler) Write(ss getty.Session, pkg interface{})
([]byte, error) {
res, ok := pkg.(*remoting.Response)
+ maxBufLength := srvConf.GettySessionParam.MaxMsgLen + impl.HEADER_LENGTH
if ok {
buf, err := (p.server.codec).EncodeResponse(res)
+ bufLength := buf.Len()
+ if bufLength > maxBufLength {
+ logger.Errorf("Data length %d too large, max payload
%d", bufLength-impl.HEADER_LENGTH, srvConf.GettySessionParam.MaxMsgLen)
+ return nil, perrors.Errorf("Data length %d too large,
max payload %d", bufLength-impl.HEADER_LENGTH,
srvConf.GettySessionParam.MaxMsgLen)
+ }
if err != nil {
logger.Warnf("binary.Write(res{%#v}) = err{%#v}", res,
perrors.WithStack(err))
return nil, perrors.WithStack(err)
@@ -124,6 +142,11 @@ func (p *RpcServerPackageHandler) Write(ss getty.Session,
pkg interface{}) ([]by
req, ok := pkg.(*remoting.Request)
if ok {
buf, err := (p.server.codec).EncodeRequest(req)
+ bufLength := buf.Len()
+ if bufLength > maxBufLength {
+ logger.Errorf("Data length %d too large, max payload
%d", bufLength-impl.HEADER_LENGTH, srvConf.GettySessionParam.MaxMsgLen)
+ return nil, perrors.Errorf("Data length %d too large,
max payload %d", bufLength-impl.HEADER_LENGTH,
srvConf.GettySessionParam.MaxMsgLen)
+ }
if err != nil {
logger.Warnf("binary.Write(req{%#v}) = err{%#v}", res,
perrors.WithStack(err))
return nil, perrors.WithStack(err)