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

release-20.1: jobs: Send results to the client when job completes #56146

Merged
merged 1 commit into from
Oct 30, 2020
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
10 changes: 10 additions & 0 deletions pkg/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,8 @@ func (sj *StartableJob) Run(ctx context.Context) error {
if err != nil {
return err
}
jobCompletedOk := false

var r tree.Datums // stores a row if we've received one.
for {
// Alternate between receiving rows and sending them. Nil channels block.
Expand All @@ -868,6 +870,9 @@ func (sj *StartableJob) Run(ctx context.Context) error {
}
case toClient <- r:
r = nil
if jobCompletedOk {
return nil
}
case <-ctx.Done():
// Launch a goroutine to continue consuming results from the job.
if resultsFromJob != nil {
Expand All @@ -887,6 +892,11 @@ func (sj *StartableJob) Run(ctx context.Context) error {
return ctx.Err()
case err := <-errCh:
// The job has completed, return its final error.
if err == nil && r != nil {
// We still have data to send to the client.
jobCompletedOk = true
continue
}
return err
}
}
Expand Down