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

Fix: write to channel should be protected with context #91

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions internal/batch/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ func Scan(ctx context.Context, r io.Reader, out chan<- net.Buffers, opts Options
}

if bufferedRows >= opts.Size { // dispatch to COPY worker & reset
if ctx.Err() != nil {
return nil
select {
case out <- bufs:
case <-ctx.Done():
return ctx.Err()
}
out <- bufs
bufs = make(net.Buffers, 0, opts.Size)
bufferedRows = 0
}
Expand All @@ -130,7 +131,11 @@ func Scan(ctx context.Context, r io.Reader, out chan<- net.Buffers, opts Options

// Finished reading input, make sure last batch goes out.
if len(bufs) > 0 {
out <- bufs
select {
case out <- bufs:
case <-ctx.Done():
return ctx.Err()
}
}

return nil
Expand Down
Loading