Skip to content

Commit e4ddcb3

Browse files
committed
libcontainerd: use healthcheck to track containerd conn
Signed-off-by: Alexander Morozov <[email protected]>
1 parent e5544fb commit e4ddcb3

File tree

10 files changed

+237
-39
lines changed

10 files changed

+237
-39
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ RUN set -x \
243243
&& rm -rf "$GOPATH"
244244

245245
# Install containerd
246-
ENV CONTAINERD_COMMIT 35a736c471ccd3ebfc7b80ceeb0ee303129acd61
246+
ENV CONTAINERD_COMMIT 4c21ad662f71af56c0e6b29c0afef72df441d1ff
247247
RUN set -x \
248248
&& export GOPATH="$(mktemp -d)" \
249249
&& git clone https://github.com/docker/containerd.git "$GOPATH/src/github.com/docker/containerd" \

Dockerfile.aarch64

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ RUN set -x \
186186
&& rm -rf "$GOPATH"
187187

188188
# Install containerd
189-
ENV CONTAINERD_COMMIT 35a736c471ccd3ebfc7b80ceeb0ee303129acd61
189+
ENV CONTAINERD_COMMIT 4c21ad662f71af56c0e6b29c0afef72df441d1ff
190190
RUN set -x \
191191
&& export GOPATH="$(mktemp -d)" \
192192
&& git clone https://github.com/docker/containerd.git "$GOPATH/src/github.com/docker/containerd" \

Dockerfile.armhf

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ RUN set -x \
184184
&& rm -rf "$GOPATH"
185185

186186
# Install containerd
187-
ENV CONTAINERD_COMMIT 35a736c471ccd3ebfc7b80ceeb0ee303129acd61
187+
ENV CONTAINERD_COMMIT 4c21ad662f71af56c0e6b29c0afef72df441d1ff
188188
RUN set -x \
189189
&& export GOPATH="$(mktemp -d)" \
190190
&& git clone https://github.com/docker/containerd.git "$GOPATH/src/github.com/docker/containerd" \

Dockerfile.ppc64le

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ RUN set -x \
204204
&& rm -rf "$GOPATH"
205205

206206
# Install containerd
207-
ENV CONTAINERD_COMMIT 35a736c471ccd3ebfc7b80ceeb0ee303129acd61
207+
ENV CONTAINERD_COMMIT 4c21ad662f71af56c0e6b29c0afef72df441d1ff
208208
RUN set -x \
209209
&& export GOPATH="$(mktemp -d)" \
210210
&& git clone https://github.com/docker/containerd.git "$GOPATH/src/github.com/docker/containerd" \

Dockerfile.s390x

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ RUN set -x \
196196
&& rm -rf "$GOPATH"
197197

198198
# Install containerd
199-
ENV CONTAINERD_COMMIT 35a736c471ccd3ebfc7b80ceeb0ee303129acd61
199+
ENV CONTAINERD_COMMIT 4c21ad662f71af56c0e6b29c0afef72df441d1ff
200200
RUN set -x \
201201
&& export GOPATH="$(mktemp -d)" \
202202
&& git clone https://github.com/docker/containerd.git "$GOPATH/src/github.com/docker/containerd" \

Dockerfile.simple

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ RUN set -x \
6868
&& rm -rf "$GOPATH"
6969

7070
# Install containerd
71-
ENV CONTAINERD_COMMIT 35a736c471ccd3ebfc7b80ceeb0ee303129acd61
71+
ENV CONTAINERD_COMMIT 4c21ad662f71af56c0e6b29c0afef72df441d1ff
7272
RUN set -x \
7373
&& export GOPATH="$(mktemp -d)" \
7474
&& git clone https://github.com/docker/containerd.git "$GOPATH/src/github.com/docker/containerd" \

hack/vendor.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ clone git google.golang.org/cloud dae7e3d993bc3812a2185af60552bb6b847e52a0 https
141141
clone git github.com/docker/docker-credential-helpers v0.3.0
142142

143143
# containerd
144-
clone git github.com/docker/containerd 35a736c471ccd3ebfc7b80ceeb0ee303129acd61
144+
clone git github.com/docker/containerd 4c21ad662f71af56c0e6b29c0afef72df441d1ff
145145

146146
# cluster
147147
clone git github.com/docker/swarmkit 27fbaef4ceed648bb575969ccc9083a6e104a719

libcontainerd/remote_linux.go

+38-32
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@ import (
2525
"golang.org/x/net/context"
2626
"google.golang.org/grpc"
2727
"google.golang.org/grpc/grpclog"
28+
"google.golang.org/grpc/health/grpc_health_v1"
2829
"google.golang.org/grpc/transport"
2930
)
3031

3132
const (
32-
maxConnectionRetryCount = 3
33-
connectionRetryDelay = 3 * time.Second
34-
containerdShutdownTimeout = 15 * time.Second
35-
containerdBinary = "docker-containerd"
36-
containerdPidFilename = "docker-containerd.pid"
37-
containerdSockFilename = "docker-containerd.sock"
38-
containerdStateDir = "containerd"
39-
eventTimestampFilename = "event.ts"
33+
maxConnectionRetryCount = 3
34+
connectionRetryDelay = 3 * time.Second
35+
containerdHealthCheckTimeout = 3 * time.Second
36+
containerdShutdownTimeout = 15 * time.Second
37+
containerdBinary = "docker-containerd"
38+
containerdPidFilename = "docker-containerd.pid"
39+
containerdSockFilename = "docker-containerd.sock"
40+
containerdStateDir = "containerd"
41+
eventTimestampFilename = "event.ts"
4042
)
4143

4244
type remote struct {
@@ -134,37 +136,41 @@ func (r *remote) UpdateOptions(options ...RemoteOption) error {
134136

135137
func (r *remote) handleConnectionChange() {
136138
var transientFailureCount = 0
137-
state := grpc.Idle
139+
140+
ticker := time.NewTicker(500 * time.Millisecond)
141+
defer ticker.Stop()
142+
healthClient := grpc_health_v1.NewHealthClient(r.rpcConn)
143+
138144
for {
139-
s, err := r.rpcConn.WaitForStateChange(context.Background(), state)
140-
if err != nil {
141-
break
145+
<-ticker.C
146+
ctx, cancel := context.WithTimeout(context.Background(), containerdHealthCheckTimeout)
147+
_, err := healthClient.Check(ctx, &grpc_health_v1.HealthCheckRequest{})
148+
cancel()
149+
if err == nil {
150+
continue
142151
}
143-
state = s
144-
logrus.Debugf("libcontainerd: containerd connection state change: %v", s)
152+
153+
logrus.Debugf("libcontainerd: containerd health check returned error: %v", err)
145154

146155
if r.daemonPid != -1 {
147-
switch state {
148-
case grpc.TransientFailure:
149-
// Reset state to be notified of next failure
150-
transientFailureCount++
151-
if transientFailureCount >= maxConnectionRetryCount {
152-
transientFailureCount = 0
153-
if utils.IsProcessAlive(r.daemonPid) {
154-
utils.KillProcess(r.daemonPid)
155-
}
156-
<-r.daemonWaitCh
157-
if err := r.runContainerdDaemon(); err != nil { //FIXME: Handle error
158-
logrus.Errorf("libcontainerd: error restarting containerd: %v", err)
159-
}
160-
} else {
161-
state = grpc.Idle
162-
time.Sleep(connectionRetryDelay)
163-
}
164-
case grpc.Shutdown:
156+
if strings.Contains(err.Error(), "is closing") {
165157
// Well, we asked for it to stop, just return
166158
return
167159
}
160+
// all other errors are transient
161+
// Reset state to be notified of next failure
162+
transientFailureCount++
163+
if transientFailureCount >= maxConnectionRetryCount {
164+
transientFailureCount = 0
165+
if utils.IsProcessAlive(r.daemonPid) {
166+
utils.KillProcess(r.daemonPid)
167+
}
168+
<-r.daemonWaitCh
169+
if err := r.runContainerdDaemon(); err != nil { //FIXME: Handle error
170+
logrus.Errorf("libcontainerd: error restarting containerd: %v", err)
171+
}
172+
continue
173+
}
168174
}
169175
}
170176
}

vendor/src/google.golang.org/grpc/health/grpc_health_v1/health.pb.go

+172
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
syntax = "proto3";
2+
3+
package grpc.health.v1;
4+
5+
message HealthCheckRequest {
6+
string service = 1;
7+
}
8+
9+
message HealthCheckResponse {
10+
enum ServingStatus {
11+
UNKNOWN = 0;
12+
SERVING = 1;
13+
NOT_SERVING = 2;
14+
}
15+
ServingStatus status = 1;
16+
}
17+
18+
service Health{
19+
rpc Check(HealthCheckRequest) returns (HealthCheckResponse);
20+
}

0 commit comments

Comments
 (0)