Skip to content

Commit

Permalink
Merge pull request #91 from timescale/vperez/fix-#86
Browse files Browse the repository at this point in the history
Fix: write to channel should be protected with context
  • Loading branch information
MetalBlueberry authored Nov 11, 2024
2 parents a65d867 + 2e52f41 commit 3efae78
Showing 1 changed file with 9 additions and 4 deletions.
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

0 comments on commit 3efae78

Please sign in to comment.