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

Bugfix: Return notebook worker to the pool when query is cancelled. #3252

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion services/notebook/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,16 @@ func (self *NotebookWorker) RegisterWorker(

case job, ok := <-job_chan:
if !ok {
return errors.New("Cancellation")
job.Done("", errors.New("Cancellation"))
return nil
}

request := &NotebookRequest{}
err := json.Unmarshal([]byte(job.Job), request)
if err != nil {
logger.Error("NotebookManager: Invalid job request in worker: %v: %v",
err, job.Job)
job.Done("", err)
continue
}

Expand Down Expand Up @@ -570,6 +572,8 @@ func (self *NotebookWorker) startNanny(
}
scope.Log("ERROR:NotebookManager: Detected cell %v is cancelled. Stopping.", cell_id)
notifier.NotifyDirectListener(cell_id)

return
}
}
}
Expand Down
22 changes: 17 additions & 5 deletions services/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,32 @@ func (self *Scheduler) Schedule(ctx context.Context,
})

for _, w := range available_workers {
// The worker can get back to the pool immediately while
// we wait for our consumer.
job.Done = func(result string, err error) {
result_chan <- services.JobResponse{
w.SetBusy(false)
w.SetRequest(vfilter.Null{})
defer close(result_chan)

select {
case <-ctx.Done():
return

case result_chan <- services.JobResponse{
Job: result,
Err: err,
}:
}

w.SetRequest(vfilter.Null{})
w.SetBusy(false)
close(result_chan)
}

select {

// If the caller is cancelled we can return the worker to
// the pool.
case <-ctx.Done():
self.mu.Unlock()
w.SetBusy(false)
w.SetRequest(vfilter.Null{})
close(result_chan)
return result_chan, errors.New("Cancelled")

Expand Down
Loading