From 90b0d9fac3ac951617793cae6c672f38656ad52a Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 6 Sep 2026 16:28:03 -0600 Subject: [PATCH] Serve grpc.health.v1.Health on the build session so BuildKit does not drop it --- lib/proto/health.proto | 22 ++++++++++++++++++++++ lib/session.js | 20 ++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/proto/health.proto diff --git a/lib/proto/health.proto b/lib/proto/health.proto new file mode 100644 index 0000000..794ed9c --- /dev/null +++ b/lib/proto/health.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; + +package grpc.health.v1; + +message HealthCheckRequest { + string service = 1; +} + +message HealthCheckResponse { + enum ServingStatus { + UNKNOWN = 0; + SERVING = 1; + NOT_SERVING = 2; + SERVICE_UNKNOWN = 3; + } + ServingStatus status = 1; +} + +service Health { + rpc Check(HealthCheckRequest) returns (HealthCheckResponse); + rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse); +} diff --git a/lib/session.js b/lib/session.js index 495c0e7..5372ebc 100644 --- a/lib/session.js +++ b/lib/session.js @@ -51,6 +51,26 @@ function withSession(docker, auth, handler) { }, }); + // BuildKit health-checks the session's gRPC connection (grpc.health.v1.Health/Check) + // and tears the session down after a couple of consecutive failed checks + // (moby/buildkit session/grpc.go). Without a Health service the check returns + // UNIMPLEMENTED, so BuildKit drops the session before the build's first vertex and + // the build stalls (typically at "load metadata for "). Serve SERVING so + // the session stays up for the lifetime of the build. + const healthPkg = protoLoader.loadSync( + path.resolve(__dirname, "proto", "health.proto") + ); + const healthService = grpc.loadPackageDefinition(healthPkg); + + server.addService(healthService.grpc.health.v1.Health.service, { + Check(call, callback) { + callback(null, { status: "SERVING" }); + }, + Watch(call) { + call.write({ status: "SERVING" }); + }, + }); + function done() { server.forceShutdown(); socket.end();