-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fixup gRPC buffer overflow bug with unit test. #3376
fix: fixup gRPC buffer overflow bug with unit test. #3376
Conversation
c172672
to
895fbf0
Compare
@@ -35,7 +35,7 @@ func tmpDir(c *C) string { | |||
// limit the size of the address while retaining some of the properties | |||
// of the original directory name | |||
hs := adler32.Checksum([]byte(c.TestName())) | |||
d, err := os.MkdirTemp("", fmt.Sprintf("%08x%.20s", hs, c.TestName())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to make these temp files easier to find. Having the filename hash first can be really confusing when using ls
and an alphabetical sort.
t := time.NewTicker(s.tailTickDuration) | ||
for { | ||
n, err := buf.ReadFrom(fh) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixup misuse of bytes.Buffer
: bytes.Buffer
will grow to size of write regardless of backing buffer capacity.
@@ -219,7 +218,7 @@ func (s *processServiceServer) streamOutput(ss sender, p *process, fh *os.File) | |||
<-t.C | |||
continue | |||
} | |||
o := &Output{Output: buf.String()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performs an extra allocation for the string object which may add measurable overhead considering how large the buffer is (2MB). May want to convert this code to a 2 thread bucket brigade at some point.
@@ -449,3 +449,37 @@ func (s *KanXSuite) TestCreateProcess_Exit2(c *C) { | |||
c.Assert(p0.GetExitErr(), Equals, "signal: killed") | |||
c.Assert(p0.GetExitCode(), Equals, int64(-1)) | |||
} | |||
|
|||
func (s *KanXSuite) TestCreateProcess_BufferOverflow_1(c *C) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test that buffer does not overflow.
5e65328
to
3073c38
Compare
c4b07b6
to
91b53a4
Compare
Signed-off-by: Aaron Alpar <[email protected]>
91b53a4
to
972a369
Compare
Signed-off-by: Aaron Alpar <[email protected]>
Signed-off-by: Aaron Alpar <[email protected]>
Signed-off-by: Aaron Alpar <[email protected]>
Change Overview
gRPC has a over-the-wire buffer limit of 4MB. gRPC buffer overflow errors can occur if this figure is use as a before the wire buffer measure as gRPC adds overhead (JSON overhead) when sending messages from gRPC API clients.
This fix just divides the gRPC buffer limit in half (2MB) which is much smaller than the theoretical max (theoretical_max = 4MB - protocol overhead) but intuitively large enough to hold enough data.
This also includes a fix for using
bytes.Buffer
as a circular buffer, which its not very good at. Instead a[]byte
buffer is used. If performance is a concern then the buffer copy should be split across 2 threads in a bucket brigade.Pull request type
Please check the type of change your PR introduces:
Issues
There is no github issue for this fix.
Test Plan