소스 검색

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 년 전
부모
커밋
eadf0b0259
1개의 변경된 파일5개의 추가작업 그리고 1개의 파일을 삭제
  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{})
 
 	go func() {
-		result <- work(stopper)
+		value := work(stopper)
+		select {
+		case result <- value:
+		case <-stopper:
+		}
 	}()
 
 	select {