Ensure shim start & exit events are sent in right order
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
0f0f3b69dc
commit
8ca92a2aa8
@ -23,6 +23,11 @@ import (
|
|||||||
type initProcess struct {
|
type initProcess struct {
|
||||||
sync.WaitGroup
|
sync.WaitGroup
|
||||||
|
|
||||||
|
// mu is used to ensure that `Start()` and `Exited()` calls return in
|
||||||
|
// the right order when invoked in separate go routines.
|
||||||
|
// This is the case within the shim implementation as it makes use of
|
||||||
|
// the reaper interface.
|
||||||
|
mu sync.Mutex
|
||||||
id string
|
id string
|
||||||
bundle string
|
bundle string
|
||||||
console console.Console
|
console console.Console
|
||||||
@ -139,12 +144,16 @@ func (p *initProcess) ContainerStatus(ctx context.Context) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *initProcess) Start(context context.Context) error {
|
func (p *initProcess) Start(context context.Context) error {
|
||||||
|
p.mu.Lock()
|
||||||
|
defer p.mu.Unlock()
|
||||||
return p.runc.Start(context, p.id)
|
return p.runc.Start(context, p.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *initProcess) Exited(status int) {
|
func (p *initProcess) Exited(status int) {
|
||||||
|
p.mu.Lock()
|
||||||
p.status = status
|
p.status = status
|
||||||
p.exited = time.Now()
|
p.exited = time.Now()
|
||||||
|
p.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *initProcess) Delete(context context.Context) error {
|
func (p *initProcess) Delete(context context.Context) error {
|
||||||
|
@ -56,12 +56,12 @@ func (s *Service) Create(ctx context.Context, r *shimapi.CreateRequest) (*shimap
|
|||||||
ExitCh: make(chan int, 1),
|
ExitCh: make(chan int, 1),
|
||||||
}
|
}
|
||||||
reaper.Default.Register(pid, cmd)
|
reaper.Default.Register(pid, cmd)
|
||||||
go s.waitExit(process, pid, cmd)
|
|
||||||
s.events <- &container.Event{
|
s.events <- &container.Event{
|
||||||
Type: container.Event_CREATE,
|
Type: container.Event_CREATE,
|
||||||
ID: r.ID,
|
ID: r.ID,
|
||||||
Pid: uint32(pid),
|
Pid: uint32(pid),
|
||||||
}
|
}
|
||||||
|
go s.waitExit(process, pid, cmd)
|
||||||
return &shimapi.CreateResponse{
|
return &shimapi.CreateResponse{
|
||||||
Pid: uint32(pid),
|
Pid: uint32(pid),
|
||||||
}, nil
|
}, nil
|
||||||
@ -115,12 +115,12 @@ func (s *Service) Exec(ctx context.Context, r *shimapi.ExecRequest) (*shimapi.Ex
|
|||||||
}
|
}
|
||||||
reaper.Default.RegisterNL(pid, cmd)
|
reaper.Default.RegisterNL(pid, cmd)
|
||||||
reaper.Default.Unlock()
|
reaper.Default.Unlock()
|
||||||
go s.waitExit(process, pid, cmd)
|
|
||||||
s.events <- &container.Event{
|
s.events <- &container.Event{
|
||||||
Type: container.Event_EXEC_ADDED,
|
Type: container.Event_EXEC_ADDED,
|
||||||
ID: s.id,
|
ID: s.id,
|
||||||
Pid: uint32(pid),
|
Pid: uint32(pid),
|
||||||
}
|
}
|
||||||
|
go s.waitExit(process, pid, cmd)
|
||||||
return &shimapi.ExecResponse{
|
return &shimapi.ExecResponse{
|
||||||
Pid: uint32(pid),
|
Pid: uint32(pid),
|
||||||
}, nil
|
}, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user