-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update reaper for multiple subscribers #1452
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"github.com/containerd/containerd/namespaces" | ||
"github.com/containerd/containerd/reaper" | ||
"github.com/containerd/containerd/runtime" | ||
runc "github.com/containerd/go-runc" | ||
google_protobuf "github.com/golang/protobuf/ptypes/empty" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
|
@@ -48,7 +49,9 @@ func NewService(path, namespace, workDir string, publisher events.Publisher) (*S | |
namespace: namespace, | ||
context: context, | ||
workDir: workDir, | ||
ec: reaper.Default.Subscribe(), | ||
} | ||
go s.processExits() | ||
if err := s.initPlatform(); err != nil { | ||
return nil, errors.Wrap(err, "failed to initialized platform behavior") | ||
} | ||
|
@@ -70,31 +73,27 @@ type Service struct { | |
mu sync.Mutex | ||
processes map[string]process | ||
events chan interface{} | ||
eventsMu sync.Mutex | ||
deferredEvent interface{} | ||
namespace string | ||
context context.Context | ||
ec chan runc.Exit | ||
|
||
workDir string | ||
platform platform | ||
} | ||
|
||
func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (*shimapi.CreateTaskResponse, error) { | ||
s.mu.Lock() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use Otherwise, move it back after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
defer s.mu.Unlock() | ||
process, err := newInitProcess(ctx, s.platform, s.path, s.namespace, s.workDir, r) | ||
if err != nil { | ||
return nil, errdefs.ToGRPC(err) | ||
} | ||
s.mu.Lock() | ||
// save the main task id and bundle to the shim for additional requests | ||
s.id = r.ID | ||
s.bundle = r.Bundle | ||
pid := process.Pid() | ||
s.processes[r.ID] = process | ||
s.mu.Unlock() | ||
cmd := &reaper.Cmd{ | ||
ExitCh: make(chan struct{}), | ||
} | ||
reaper.Default.Register(pid, cmd) | ||
s.events <- &eventsapi.TaskCreate{ | ||
ContainerID: r.ID, | ||
Bundle: r.Bundle, | ||
|
@@ -108,7 +107,6 @@ func (s *Service) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (*sh | |
Checkpoint: r.Checkpoint, | ||
Pid: uint32(pid), | ||
} | ||
go s.waitExit(process, pid, cmd) | ||
return &shimapi.CreateTaskResponse{ | ||
Pid: uint32(pid), | ||
}, nil | ||
|
@@ -129,11 +127,6 @@ func (s *Service) Start(ctx context.Context, r *shimapi.StartRequest) (*shimapi. | |
} | ||
} else { | ||
pid := p.Pid() | ||
cmd := &reaper.Cmd{ | ||
ExitCh: make(chan struct{}), | ||
} | ||
reaper.Default.Register(pid, cmd) | ||
go s.waitExit(p, pid, cmd) | ||
s.events <- &eventsapi.TaskExecStarted{ | ||
ContainerID: s.id, | ||
ExecID: r.ID, | ||
|
@@ -392,17 +385,27 @@ func (s *Service) deleteProcess(id string) { | |
s.mu.Unlock() | ||
} | ||
|
||
func (s *Service) waitExit(p process, pid int, cmd *reaper.Cmd) { | ||
status, _ := reaper.Default.WaitPid(pid) | ||
p.SetExited(status) | ||
func (s *Service) processExits() { | ||
for e := range s.ec { | ||
s.checkProcesses(e) | ||
} | ||
} | ||
|
||
reaper.Default.Delete(pid) | ||
s.events <- &eventsapi.TaskExit{ | ||
ContainerID: s.id, | ||
ID: p.ID(), | ||
Pid: uint32(pid), | ||
ExitStatus: uint32(status), | ||
ExitedAt: p.ExitedAt(), | ||
func (s *Service) checkProcesses(e runc.Exit) { | ||
s.mu.Lock() | ||
defer s.mu.Unlock() | ||
for _, p := range s.processes { | ||
if p.Pid() == e.Pid { | ||
p.SetExited(e.Status) | ||
s.events <- &eventsapi.TaskExit{ | ||
ContainerID: s.id, | ||
ID: p.ID(), | ||
Pid: uint32(e.Pid), | ||
ExitStatus: uint32(e.Status), | ||
ExitedAt: p.ExitedAt(), | ||
} | ||
return | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use failed preconditions here? Although I guess not found make it easier, only need to check against one type of error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its this way because we map no such process syscall error to NotFound