浏览代码

fix: a runner can now tell the webserver where it actually is

registerWithWebServer hardcoded the advertised address as
"localhost:<grpc_port>". That is only true when the runner and the webserver
share a host. Split across two machines it tells the webserver to reach the
runner on the webserver's own box, where nothing is listening - and the
registration still succeeds and the runner still reports online, so the
registry looks healthy while dispatches go nowhere.

advertise_address (env ADVERTISE_ADDRESS) now overrides it. Empty keeps the
old string exactly, so a single-host deployment is unaffected.
fszontagh 3 周之前
父节点
当前提交
ccfd8118fb
共有 3 个文件被更改,包括 13 次插入 和 1 次删除
  1. 1 0
      config/runner.json
  2. 6 1
      src/runner/runner_service.cpp
  3. 6 0
      src/runner/runner_service.hpp

+ 1 - 0
config/runner.json

@@ -1,6 +1,7 @@
 {
   "grpc_port": 9011,
   "runner_id": "${RUNNER_ID:runner-1}",
+  "advertise_address": "${ADVERTISE_ADDRESS:}",
   "webserver_address": "${WEBSERVER_ADDRESS:localhost:8090}",
   "node_sync_address": "${NODE_SYNC_ADDRESS:localhost:9012}",
   "credential_service_address": "${CREDENTIAL_SERVICE_ADDRESS:localhost:9013}",

+ 6 - 1
src/runner/runner_service.cpp

@@ -703,6 +703,7 @@ RunnerServiceConfig RunnerService::loadConfig(const std::filesystem::path& path)
 
         config.grpc_port = cfg.getOr<int>("grpc_port", 9003);
         config.runner_id = cfg.getOr<std::string>("runner_id", "runner-1");
+        config.advertise_address = cfg.getOr<std::string>("advertise_address", "");
         config.webserver_address = cfg.getOr<std::string>("webserver_address", "localhost:8080");
         config.node_sync_address = cfg.getOr<std::string>("node_sync_address", "localhost:9002");
         config.credential_service_address = cfg.getOr<std::string>("credential_service_address", "localhost:9003");
@@ -856,7 +857,11 @@ bool RunnerService::registerWithWebServer() {
     // Use HTTP to register with webserver
     nlohmann::json body;
     body["id"] = config_.runner_id;
-    body["address"] = "localhost:" + std::to_string(config_.grpc_port);
+    // localhost is only correct when the webserver shares this host. Where it
+    // does not, the webserver would dial its own machine and find nothing.
+    body["address"] = config_.advertise_address.empty()
+                          ? "localhost:" + std::to_string(config_.grpc_port)
+                          : config_.advertise_address;
 
     nlohmann::json capabilities;
     std::vector<std::string> node_types;

+ 6 - 0
src/runner/runner_service.hpp

@@ -86,6 +86,12 @@ private:
 // Runner service configuration
 struct RunnerServiceConfig {
     int grpc_port = 9003;              // Runner's own gRPC server port
+
+    // What this runner tells the webserver to reach it on. Empty means
+    // "localhost:<grpc_port>", which is right only when the two share a host.
+    // With the webserver on another machine that address points the webserver
+    // back at itself, so every dispatch goes to a port nothing is listening on.
+    std::string advertise_address;
     std::string runner_id = "runner-1";
     std::string webserver_address = "localhost:8080";    // HTTP for registration
     std::string node_sync_address = "localhost:9002";    // gRPC for node sync