mirror of
https://github.com/minio/minio.git
synced 2025-05-21 09:33:50 -04:00
rpc: Avoid using Pool since it conflicts with http2 (#7467)
A race is detected between a bytes.Buffer generated with cmd/rpc.Pool and http2 module. An issue is raised in golang (https://github.com/golang/go/issues/31192). Meanwhile, this commit disables Pool in RPC code and it generates a new 1kb of bytes.Buffer for each RPC call.
This commit is contained in:
parent
ef791764e0
commit
4c23e6fa55
@ -17,6 +17,7 @@
|
|||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
@ -49,8 +50,7 @@ func (client *Client) Call(serviceMethod string, args, reply interface{}) error
|
|||||||
return fmt.Errorf("rpc reply must be a pointer type, but found %v", replyKind)
|
return fmt.Errorf("rpc reply must be a pointer type, but found %v", replyKind)
|
||||||
}
|
}
|
||||||
|
|
||||||
argBuf := bufPool.Get()
|
argBuf := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||||
defer bufPool.Put(argBuf)
|
|
||||||
|
|
||||||
if err := gobEncodeBuf(args, argBuf); err != nil {
|
if err := gobEncodeBuf(args, argBuf); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -61,8 +61,7 @@ func (client *Client) Call(serviceMethod string, args, reply interface{}) error
|
|||||||
ArgBytes: argBuf.Bytes(),
|
ArgBytes: argBuf.Bytes(),
|
||||||
}
|
}
|
||||||
|
|
||||||
reqBuf := bufPool.Get()
|
reqBuf := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||||
defer bufPool.Put(reqBuf)
|
|
||||||
if err := gob.NewEncoder(reqBuf).Encode(callRequest); err != nil {
|
if err := gob.NewEncoder(reqBuf).Encode(callRequest); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,6 @@ var errorType = reflect.TypeOf((*error)(nil)).Elem()
|
|||||||
// reflect.Type of Authenticator interface.
|
// reflect.Type of Authenticator interface.
|
||||||
var authenticatorType = reflect.TypeOf((*Authenticator)(nil)).Elem()
|
var authenticatorType = reflect.TypeOf((*Authenticator)(nil)).Elem()
|
||||||
|
|
||||||
var bufPool = NewPool()
|
|
||||||
|
|
||||||
func gobEncodeBuf(e interface{}, buf *bytes.Buffer) error {
|
func gobEncodeBuf(e interface{}, buf *bytes.Buffer) error {
|
||||||
return gob.NewEncoder(buf).Encode(e)
|
return gob.NewEncoder(buf).Encode(e)
|
||||||
}
|
}
|
||||||
@ -239,8 +237,8 @@ func (server *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
callResponse := CallResponse{}
|
callResponse := CallResponse{}
|
||||||
buf := bufPool.Get()
|
|
||||||
defer bufPool.Put(buf)
|
buf := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||||
|
|
||||||
if err := server.call(callRequest.Method, callRequest.ArgBytes, buf); err != nil {
|
if err := server.call(callRequest.Method, callRequest.ArgBytes, buf); err != nil {
|
||||||
callResponse.Error = err.Error()
|
callResponse.Error = err.Error()
|
||||||
|
@ -253,8 +253,7 @@ func TestServerCall(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
buf := bufPool.Get()
|
buf := bytes.NewBuffer([]byte{})
|
||||||
defer bufPool.Put(buf)
|
|
||||||
|
|
||||||
err := testCase.server.call(testCase.serviceMethod, testCase.argBytes, buf)
|
err := testCase.server.call(testCase.serviceMethod, testCase.argBytes, buf)
|
||||||
expectErr := (err != nil)
|
expectErr := (err != nil)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user