Commit 3430adb5 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

restart x0 on crash

parent 7447de9c
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#include <fnordmetric/http/httprequest.h>
#include <fnordmetric/http/httpresponse.h>
#include <fnordmetric/util/runtimeexception.h>
#include <fnordmetric/util/wallclock.h>
#include <xzero/TimeSpan.h>
#include <xzero/http/HttpRequest.h>
#include <xzero/http/HttpResponse.h>
@@ -100,6 +101,33 @@ HTTPServer::HTTPServer(
    request_scheduler_(request_scheduler) {}

void HTTPServer::listen(int port) {
  auto last_crash = util::WallClock::unixMillis();

start_x0:

  try {
    listenOrCrash(port);
  } catch (fnordmetric::util::RuntimeException& e) {
    fnordmetric::env()->logger()->printf(
        "ERROR",
        "HTTP server crashed: %s",
        e.getMessage().c_str());

    if (util::WallClock::unixMillis() - last_crash < 30000) {
      fnordmetric::env()->logger()->printf(
          "ERROR",
          "HTTP server crashing too fast, aborting");

      throw;
    } else {
      fnordmetric::env()->logger()->printf("INFO", "Restarting HTTP server");
      last_crash = util::WallClock::unixMillis();
      goto start_x0;
    }
  }
}

void HTTPServer::listenOrCrash(int port) {
  xzero::IPAddress bind("0.0.0.0");
  xzero::TimeSpan idle = xzero::TimeSpan::fromSeconds(30);
  xzero::HttpService http;
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ public:
  void listen(int port);

protected:
  void listenOrCrash(int port);
  std::vector<std::unique_ptr<HTTPHandler>> handlers_;
  TaskScheduler* request_scheduler_;
};
+1 −2
Original line number Diff line number Diff line
@@ -14,8 +14,6 @@
    - group over doc: GROUP OVER TIMEWINDOW(time_window, step) oder so

[ SQL ]
    - proper thread/worker pool
    - free scratchpads in group by
    - no more "UNKNOWN TOKEN"
    - match function names case-insensitively
    - sql time helpers (1hour, etc)
@@ -50,6 +48,7 @@
    - do I need an external database

[ feature q ]
    - max threads in takscheduler?
    - functions: variance, stddev, nth_derivate,
    - union
    - cross join