From b10d68c5b40c204fa07db3613a2593a92fadbd55 Mon Sep 17 00:00:00 2001 From: Matthieu Gusmini <111724849+matthieugusmini@users.noreply.github.com> Date: Mon, 13 Feb 2023 15:19:23 +0900 Subject: [PATCH] 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`. --- client.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client.go b/client.go index 5108a47..00e99a5 100644 --- a/client.go +++ b/client.go @@ -15,6 +15,8 @@ import ( "golang.org/x/exp/slog" ) +const MaxScanTokenSize = 1024 * 1024 + var ( // ErrNotConnected is returned when trying to stop the client from streaming // CDC events while it is not running. @@ -245,6 +247,11 @@ func (c *Client) requestData(database, table, version, gtid string) (<-chan Even func (c *Client) handleEvents(data chan<- Event) error { var readSchema bool scanner := bufio.NewScanner(c.conn) + // HOTFIX: Replace by a `bufio.Reader` instead since it seems to be the + // preferred method. + // See https://pkg.go.dev/bufio#Scanner + buf := make([]byte, 0, MaxScanTokenSize) + scanner.Buffer(buf, MaxScanTokenSize) for scanner.Scan() { token := scanner.Bytes()