sched: Fix taskDone chan deadlock

This commit is contained in:
Łukasz Magiera 2021-10-03 17:09:43 +02:00
parent b87142ec8e
commit 9af82f2d68

View File

@ -475,6 +475,7 @@ func (sw *schedWorker) startProcessingTask(req *workerRequest) error {
case sw.taskDone <- struct{}{}: case sw.taskDone <- struct{}{}:
case <-sh.closing: case <-sh.closing:
log.Warnf("scheduler closed while sending response (prepare error: %+v)", err) log.Warnf("scheduler closed while sending response (prepare error: %+v)", err)
default: // there is a notification pending already
} }
select { select {
@ -496,6 +497,7 @@ func (sw *schedWorker) startProcessingTask(req *workerRequest) error {
select { select {
case sw.taskDone <- struct{}{}: case sw.taskDone <- struct{}{}:
case <-sh.closing: case <-sh.closing:
default: // there is a notification pending already
} }
// Do the work! // Do the work!
@ -550,6 +552,7 @@ func (sw *schedWorker) startProcessingReadyTask(req *workerRequest) error {
case sw.taskDone <- struct{}{}: case sw.taskDone <- struct{}{}:
case <-sh.closing: case <-sh.closing:
log.Warnf("scheduler closed while sending response (prepare error: %+v)", err) log.Warnf("scheduler closed while sending response (prepare error: %+v)", err)
default: // there is a notification pending already
} }
w.lk.Unlock() w.lk.Unlock()