Sfoglia il codice sorgente

Fix goroutine leak in deadline

If the deadline timed out then the worker goroutine might have been
leaked trying to write to `result` which had no readers.
Evan Huus 6 anni fa
parent
commit
eadf0b0259
1 ha cambiato i file con 5 aggiunte e 1 eliminazioni
  1. 5 1
      deadline/deadline.go

+ 5 - 1
deadline/deadline.go

@@ -32,7 +32,11 @@ func (d *Deadline) Run(work func(<-chan struct{}) error) error {
 	stopper := make(chan struct{})
 	stopper := make(chan struct{})
 
 
 	go func() {
 	go func() {
-		result <- work(stopper)
+		value := work(stopper)
+		select {
+		case result <- value:
+		case <-stopper:
+		}
 	}()
 	}()
 
 
 	select {
 	select {