This repository was archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 345
Generate fatal error when cri plugin fail to start. #794
Merged
Random-Liu
merged 1 commit into
containerd:master
from
Random-Liu:panic-for-cri-start-failure
May 31, 2018
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ package server | |
| import ( | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "path/filepath" | ||
| "time" | ||
|
|
||
|
|
@@ -179,10 +180,7 @@ func (c *criService) Run() error { | |
|
|
||
| // Start event handler. | ||
| logrus.Info("Start event monitor") | ||
| eventMonitorCloseCh, err := c.eventMonitor.start() | ||
| if err != nil { | ||
| return errors.Wrap(err, "failed to start event monitor") | ||
| } | ||
| eventMonitorErrCh := c.eventMonitor.start() | ||
|
|
||
| // Start snapshot stats syncer, it doesn't need to be stopped. | ||
| logrus.Info("Start snapshots syncer") | ||
|
|
@@ -195,27 +193,32 @@ func (c *criService) Run() error { | |
|
|
||
| // Start streaming server. | ||
| logrus.Info("Start streaming server") | ||
| streamServerCloseCh := make(chan struct{}) | ||
| streamServerErrCh := make(chan error) | ||
| go func() { | ||
| if err := c.streamServer.Start(true); err != nil { | ||
| defer close(streamServerErrCh) | ||
| if err := c.streamServer.Start(true); err != nil && err != http.ErrServerClosed { | ||
| logrus.WithError(err).Error("Failed to start streaming server") | ||
| streamServerErrCh <- err | ||
| } | ||
| close(streamServerCloseCh) | ||
| }() | ||
|
|
||
| // Set the server as initialized. GRPC services could start serving traffic. | ||
| c.initialized.Set() | ||
|
|
||
| var eventMonitorErr, streamServerErr error | ||
| // Stop the whole CRI service if any of the critical service exits. | ||
| select { | ||
| case <-eventMonitorCloseCh: | ||
| case <-streamServerCloseCh: | ||
| case eventMonitorErr = <-eventMonitorErrCh: | ||
| case streamServerErr = <-streamServerErrCh: | ||
| } | ||
| if err := c.Close(); err != nil { | ||
| return errors.Wrap(err, "failed to stop cri service") | ||
| } | ||
|
|
||
| <-eventMonitorCloseCh | ||
| // If the error is set above, err from channel must be nil here, because | ||
| // the channel is supposed to be closed. Or else, we wait and set it. | ||
| if err := <-eventMonitorErrCh; err != nil { | ||
| eventMonitorErr = err | ||
| } | ||
| logrus.Info("Event monitor stopped") | ||
| // There is a race condition with http.Server.Serve. | ||
| // When `Close` is called at the same time with `Serve`, `Close` | ||
|
|
@@ -227,18 +230,27 @@ func (c *criService) Run() error { | |
| // is fixed. | ||
| const streamServerStopTimeout = 2 * time.Second | ||
| select { | ||
| case <-streamServerCloseCh: | ||
| case err := <-streamServerErrCh: | ||
| if err != nil { | ||
| streamServerErr = err | ||
|
Member
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. same comment as above ..
Member
Author
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. ditto. Actually, I plan to move the channel wait logic into the stop function, which should make things more clear. Basically what we are doing is:
Member
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. kk cool |
||
| } | ||
| logrus.Info("Stream server stopped") | ||
| case <-time.After(streamServerStopTimeout): | ||
| logrus.Errorf("Stream server is not stopped in %q", streamServerStopTimeout) | ||
| } | ||
| if eventMonitorErr != nil { | ||
| return errors.Wrap(eventMonitorErr, "event monitor error") | ||
| } | ||
| if streamServerErr != nil { | ||
| return errors.Wrap(streamServerErr, "stream server error") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Stop stops the CRI service. | ||
| // Close stops the CRI service. | ||
| // TODO(random-liu): Make close synchronous. | ||
| func (c *criService) Close() error { | ||
| logrus.Info("Stop CRI service") | ||
| // TODO(random-liu): Make event monitor stop synchronous. | ||
| c.eventMonitor.stop() | ||
| if err := c.streamServer.Stop(); err != nil { | ||
| return errors.Wrap(err, "failed to stop stream server") | ||
|
|
||
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.
you can still check if eventMonitorErrCh == nil and leave the old return message if it does, though the make chan error should always work...
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.
Yeah, don't think we need to check. :) If it is nil, it is our problem.