Skip to content

Commit b10d68c

Browse files
Increased the scanner buffer size (#7)
We need to read larger token than expected. Therefore I increased the size of the buffer used by the `bufio.Scanner`.
1 parent dcd7fe5 commit b10d68c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

client.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"golang.org/x/exp/slog"
1616
)
1717

18+
const MaxScanTokenSize = 1024 * 1024
19+
1820
var (
1921
// ErrNotConnected is returned when trying to stop the client from streaming
2022
// CDC events while it is not running.
@@ -245,6 +247,11 @@ func (c *Client) requestData(database, table, version, gtid string) (<-chan Even
245247
func (c *Client) handleEvents(data chan<- Event) error {
246248
var readSchema bool
247249
scanner := bufio.NewScanner(c.conn)
250+
// HOTFIX: Replace by a `bufio.Reader` instead since it seems to be the
251+
// preferred method.
252+
// See https://pkg.go.dev/bufio#Scanner
253+
buf := make([]byte, 0, MaxScanTokenSize)
254+
scanner.Buffer(buf, MaxScanTokenSize)
248255
for scanner.Scan() {
249256
token := scanner.Bytes()
250257

0 commit comments

Comments
 (0)