container: host async wait

This commit is contained in:
criyle 2021-03-29 22:49:40 -07:00
parent 91dae1dfc6
commit 3b55a156bc
2 changed files with 30 additions and 3 deletions

View File

@ -82,6 +82,8 @@ type container struct {
recvCh chan recvReply
sendCh chan sendCmd
execveWaitCh chan execveWait
}
type recvReply struct {
@ -222,9 +224,12 @@ func (b *Builder) startContainer() (*container, error) {
recvCh: make(chan recvReply, 1),
sendCh: make(chan sendCmd, 1),
done: make(chan struct{}),
execveWaitCh: make(chan execveWait, 1),
}
go c.sendLoop()
go c.recvLoop()
go c.execveWaitLoop()
return c, nil
}

View File

@ -118,8 +118,29 @@ func (c *container) execveWait(ctx context.Context, sTime time.Time, result chan
mTime := time.Now()
// wait for result / cancel
go func() {
defer c.mu.Unlock()
c.execveWaitCh <- execveWait{
ctx: ctx,
sTime: sTime,
mTime: mTime,
result: result,
}
}
type execveWait struct {
ctx context.Context
sTime time.Time
mTime time.Time
result chan runner.Result
}
func (c *container) execveWaitLoop() {
for {
waitParam := <-c.execveWaitCh
ctx := waitParam.ctx
sTime := waitParam.sTime
mTime := waitParam.mTime
result := waitParam.result
select {
case <-c.done: // socket error
result <- convertReplyResult(reply{}, sTime, mTime, c.err)
@ -135,7 +156,8 @@ func (c *container) execveWait(ctx context.Context, sTime time.Time, result chan
_, _, err := c.recvReply()
result <- convertReplyResult(ret.Reply, sTime, mTime, err)
}
}()
c.mu.Unlock()
}
}
func convertReplyResult(reply reply, sTime, mTime time.Time, err error) runner.Result {