Add heartbeat / automatic server cleanup code
This replaces the previous method of attempting to clean up servers when an unexpected exit occurs in the client (e.g. SIGINT or panic) by a heartbeat protocol. If the server does not hear from the connecting client within a certain interval of time (500ms in this commit), it will de-activate itself. This prevents dangling Docker Machine server processes from accumulating. Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
This commit is contained in:
@@ -77,7 +77,7 @@ type LocalBinaryExecutor struct {
|
||||
|
||||
func NewLocalBinaryPlugin(driverName string) *LocalBinaryPlugin {
|
||||
return &LocalBinaryPlugin{
|
||||
stopCh: make(chan bool, 1),
|
||||
stopCh: make(chan bool),
|
||||
addrCh: make(chan string, 1),
|
||||
Executor: &LocalBinaryExecutor{
|
||||
DriverName: driverName,
|
||||
@@ -132,13 +132,19 @@ func (lbe *LocalBinaryExecutor) Close() error {
|
||||
}
|
||||
|
||||
func stream(scanner *bufio.Scanner, streamOutCh chan<- string, stopCh <-chan bool) {
|
||||
for scanner.Scan() {
|
||||
lines := make(chan string)
|
||||
go func() {
|
||||
for scanner.Scan() {
|
||||
lines <- scanner.Text()
|
||||
}
|
||||
}()
|
||||
for {
|
||||
select {
|
||||
case <-stopCh:
|
||||
close(streamOutCh)
|
||||
return
|
||||
default:
|
||||
streamOutCh <- strings.Trim(scanner.Text(), "\n")
|
||||
case line := <-lines:
|
||||
streamOutCh <- strings.Trim(line, "\n")
|
||||
if err := scanner.Err(); err != nil {
|
||||
log.Warnf("Scanning stream: %s", err)
|
||||
}
|
||||
@@ -148,7 +154,7 @@ func stream(scanner *bufio.Scanner, streamOutCh chan<- string, stopCh <-chan boo
|
||||
|
||||
func (lbp *LocalBinaryPlugin) AttachStream(scanner *bufio.Scanner) (<-chan string, chan<- bool) {
|
||||
streamOutCh := make(chan string)
|
||||
stopCh := make(chan bool, 1)
|
||||
stopCh := make(chan bool)
|
||||
go stream(scanner, streamOutCh, stopCh)
|
||||
return streamOutCh, stopCh
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user