Skip to content

Commit

Permalink
Increased the scanner buffer size (#7)
Browse files Browse the repository at this point in the history
We need to read larger token than expected. Therefore I increased the size of the buffer used by the `bufio.Scanner`.
  • Loading branch information
matthieugusmini authored Feb 13, 2023
1 parent dcd7fe5 commit b10d68c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit b10d68c

Please sign in to comment.