@@ -15,7 +15,6 @@ import (
1515 "runtime"
1616 "strconv"
1717 "strings"
18- "sync"
1918 "syscall"
2019 "time"
2120
@@ -613,6 +612,8 @@ func (p *initProcess) goCreateMountSources(ctx context.Context) (mountSourceRequ
613612 responseCh := make (chan response )
614613
615614 ctx , cancelFn := context .WithTimeout (ctx , 1 * time .Minute )
615+ context .AfterFunc (ctx , func () { close (requestCh ) })
616+
616617 go func () {
617618 // We lock this thread because we need to setns(2) here. There is no
618619 // UnlockOSThread() here, to ensure that the Go runtime will kill this
@@ -675,8 +676,6 @@ func (p *initProcess) goCreateMountSources(ctx context.Context) (mountSourceRequ
675676 return nil , nil , err
676677 }
677678
678- // TODO: Switch to context.AfterFunc when we switch to Go 1.21.
679- var requestChCloseOnce sync.Once
680679 requestFn := func (m * configs.Mount ) (* mountSource , error ) {
681680 var err error
682681 select {
@@ -686,13 +685,13 @@ func (p *initProcess) goCreateMountSources(ctx context.Context) (mountSourceRequ
686685 if ok {
687686 return resp .src , resp .err
688687 }
688+ err = fmt .Errorf ("response channel closed unexpectedly" )
689689 case <- ctx .Done ():
690690 err = fmt .Errorf ("receive mount source context cancelled: %w" , ctx .Err ())
691691 }
692692 case <- ctx .Done ():
693693 err = fmt .Errorf ("send mount request cancelled: %w" , ctx .Err ())
694694 }
695- requestChCloseOnce .Do (func () { close (requestCh ) })
696695 return nil , err
697696 }
698697 return requestFn , cancelFn , nil
0 commit comments