osbase/supervisor: make restart sleep cancelable

Previously, if a runnable died, and immediately after also its parent,
then the parent was only restarted after waiting for both the child
and then parent restart backoff sleep. Additionally, the child was
restarted with an already canceled context.

Now, the restart sleep can be canceled, and if canceled will directly
go to CANCELED state without first starting the runnable.

Change-Id: Ie986db680d4df12d590881d1a7e468c741a732d9
Reviewed-on: https://review.monogon.dev/c/monogon/+/3714
Tested-by: Jenkins CI
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/osbase/supervisor/supervisor_processor.go b/osbase/supervisor/supervisor_processor.go
index ad39d1d..595e2be 100644
--- a/osbase/supervisor/supervisor_processor.go
+++ b/osbase/supervisor/supervisor_processor.go
@@ -507,9 +507,18 @@
 
 		// Reschedule node runnable to run after backoff.
 		go func(n *node, bo time.Duration) {
-			time.Sleep(bo)
-			s.pReq <- &processorRequest{
-				schedule: &processorRequestSchedule{dn: n.dn()},
+			select {
+			case <-time.After(bo):
+				s.pReq <- &processorRequest{
+					schedule: &processorRequestSchedule{dn: n.dn()},
+				}
+			case <-n.ctx.Done():
+				s.pReq <- &processorRequest{
+					died: &processorRequestDied{
+						dn:  n.dn(),
+						err: n.ctx.Err(),
+					},
+				}
 			}
 		}(n, bo)
 	}