avoid ctx.Done() goroutine leak in Selector.run

As spotted in #162 by a contributor, if the context is done before the
Selector.run caller has received from the channel, the spawned goroutine
may leak if blocked on a send.
This commit is contained in:
Daniel Martí 2019-02-21 17:58:08 +01:00
parent 811d6d54d3
commit 26c9acb5b1

2
sel.go
View File

@ -80,7 +80,7 @@ func (s *Selector) Do(ctxt context.Context, h cdp.Executor) error {
// are invalidated prior to finishing the selector's by, wait, check, and after // are invalidated prior to finishing the selector's by, wait, check, and after
// funcs. // funcs.
func (s *Selector) run(ctxt context.Context, h *TargetHandler) chan error { func (s *Selector) run(ctxt context.Context, h *TargetHandler) chan error {
ch := make(chan error) ch := make(chan error, 1)
go func() { go func() {
defer close(ch) defer close(ch)