Skip to content
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

bufio: buffer full #3

Closed
jhchabran opened this issue Jan 10, 2024 · 0 comments · Fixed by #4
Closed

bufio: buffer full #3

jhchabran opened this issue Jan 10, 2024 · 0 comments · Fixed by #4

Comments

@jhchabran
Copy link

Hey @bobheadxi as I was working with release tooling which uses sourcegraph/run, I stumbled across a bufio: buffer full error.

Here is a test case to reproduce the error:

// stream_test.go
func TestPOF(t *testing.T) {
	newStream := func() *streamline.Stream {
		veryLongLine := "long"
		for i := 0; i < 1000; i++ {
			veryLongLine += "loooooooong"
		}
		return streamline.New(strings.NewReader(veryLongLine))
	}

	s := newStream()
	err := s.Stream(func(line string) {
	})
	if err != nil {
		t.Log(err.Error())
		t.Fail()
	}
}

While the example here is a bit exaggerated, I got the same error while streaming the response of a curl to an API that sends back JSON, so my original case is rather legitimate.

bobheadxi added a commit that referenced this issue Jan 25, 2024
This is [effectively what `(*bufio.Reader).ReadLine`
does](https://cs.opensource.google/go/go/+/refs/tags/go1.21.6:src/bufio/bufio.go;l=407-409)
- `ReadSlice` provides a partial line if its internal buffer is full, as
indicated by `bufio.ErrBufferFull`. If we get this, we're supposed to
just keep calling `ReadSlice` until we have a complete line.

Before I applied this fix, I was able to reproduce #3 with the `wide
input` test case - after this fix, the tests pass as expected.

Closes #3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant