Skip to content

Commit

Permalink
fix(jsonrpc): Limit header size to avoid unexpected OOM
Browse files Browse the repository at this point in the history
This patch limits the max size of header to 8Mib to avoid OOM issues.

Signed-off-by: Xuewei Niu <justxuewei@apache.org>
  • Loading branch information
justxuewei committed Oct 28, 2023
1 parent cccb67d commit 3c8181a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion protocol/jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const (
DefaultHTTPRspBufferSize = 1024
// PathPrefix ...
PathPrefix = byte('/')
// Max HTTP header size in Mib
MaxHeaderSize = 8 * 1024 * 1024
)

// Server is JSON RPC server wrapper
Expand Down Expand Up @@ -121,7 +123,7 @@ func (s *Server) handlePkg(conn net.Conn) {
}

for {
bufReader := bufio.NewReader(conn)
bufReader := bufio.NewReader(io.LimitReader(conn, MaxHeaderSize))
r, err := http.ReadRequest(bufReader)
if err != nil {
logger.Warnf("[ReadRequest] error: %v", err)
Expand Down

0 comments on commit 3c8181a

Please sign in to comment.