From f56e543d7502ef85944e970ddb128cd2a1d9f075 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 7 Dec 2019 14:58:19 -0500 Subject: [PATCH] add deadlock checker and revert bencode change from long ago --- daemon/main.cpp | 36 ++++++++++++++++++++++++++++++++- include/llarp.hpp | 9 ++++++--- llarp/context.cpp | 18 +++++++++++------ llarp/router/abstractrouter.hpp | 3 +++ llarp/router/router.cpp | 5 ++++- llarp/router/router.hpp | 9 +++++++++ llarp/util/bencode.cpp | 7 ------- 7 files changed, 69 insertions(+), 18 deletions(-) diff --git a/daemon/main.cpp b/daemon/main.cpp index 9ad3cfab7..82b6cfba3 100644 --- a/daemon/main.cpp +++ b/daemon/main.cpp @@ -1,6 +1,6 @@ #include // for ensure_config #include -#include +#include #include #include #include @@ -270,6 +270,40 @@ main(int argc, char *argv[]) do { // do periodic non lokinet related tasks here + if(ctx != nullptr) + { + auto ctx_pp = llarp::Context::Get(ctx); + if(ctx_pp != nullptr) + { + if(true) // ctx_pp->IsUp() and not ctx_pp->LooksAlive()) + { + for(const auto &wtf : {"you have been visited by the mascott of the " + "deadlocked router.", + "⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣀⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠄⠄⠄⠄", + "⠄⠄⠄⠄⠄⢀⣀⣀⡀⠄⠄⠄⡠⢲⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠄⠄", + "⠄⠄⠄⠔⣈⣀⠄⢔⡒⠳⡴⠊⠄⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⣿⣿⣧⠄⠄", + "⠄⢜⡴⢑⠖⠊⢐⣤⠞⣩⡇⠄⠄⠄⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠄⠝⠛⠋⠐", + "⢸⠏⣷⠈⠄⣱⠃⠄⢠⠃⠐⡀⠄⠄⠄⠄⠙⠻⢿⣿⣿⣿⣿⣿⣿⣿⡿⠛⠸⠄⠄⠄⠄", + "⠈⣅⠞⢁⣿⢸⠘⡄⡆⠄⠄⠈⠢⡀⠄⠄⠄⠄⠄⠄⠉⠙⠛⠛⠛⠉⠉⡀⠄⠡⢀⠄⣀", + "⠄⠙⡎⣹⢸⠄⠆⢘⠁⠄⠄⠄⢸⠈⠢⢄⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠃⠄⠄⠄⠄⠄", + "⠄⠄⠑⢿⠈⢆⠘⢼⠄⠄⠄⠄⠸⢐⢾⠄⡘⡏⠲⠆⠠⣤⢤⢤⡤⠄⣖⡇⠄⠄⠄⠄⠄", + "⣴⣶⣿⣿⣣⣈⣢⣸⠄⠄⠄⠄⡾⣷⣾⣮⣤⡏⠁⠘⠊⢠⣷⣾⡛⡟⠈⠄⠄⠄⠄⠄⠄", + "⣿⣿⣿⣿⣿⠉⠒⢽⠄⠄⠄⠄⡇⣿⣟⣿⡇⠄⠄⠄⠄⢸⣻⡿⡇⡇⠄⠄⠄⠄⠄⠄⠄", + "⠻⣿⣿⣿⣿⣄⠰⢼⠄⠄⠄⡄⠁⢻⣍⣯⠃⠄⠄⠄⠄⠈⢿⣻⠃⠈⡆⡄⠄⠄⠄⠄⠄", + "⠄⠙⠿⠿⠛⣿⣶⣤⡇⠄⠄⢣⠄⠄⠈⠄⢠⠂⠄⠁⠄⡀⠄⠄⣀⠔⢁⠃⠄⠄⠄⠄⠄", + "⠄⠄⠄⠄⠄⣿⣿⣿⣿⣾⠢⣖⣶⣦⣤⣤⣬⣤⣤⣤⣴⣶⣶⡏⠠⢃⠌⠄⠄⠄⠄⠄⠄", + "⠄⠄⠄⠄⠄⠿⠿⠟⠛⡹⠉⠛⠛⠿⠿⣿⣿⣿⣿⣿⡿⠂⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄", + "⠠⠤⠤⠄⠄⣀⠄⠄⠄⠑⠠⣤⣀⣀⣀⡘⣿⠿⠙⠻⡍⢀⡈⠂⠄⠄⠄⠄⠄⠄⠄⠄⠄", + "⠄⠄⠄⠄⠄⠄⠑⠠⣠⣴⣾⣿⣿⣿⣿⣿⣿⣇⠉⠄⠻⣿⣷⣄⡀⠄⠄⠄⠄⠄⠄⠄⠄", + "file a bug report now or be cursed with this " + "annoying image in your syslog for all time."}) + { + LogError(wtf); + } + std::abort(); + } + } + } } while(ftr.wait_for(std::chrono::seconds(1)) != std::future_status::ready); main_thread.join(); diff --git a/include/llarp.hpp b/include/llarp.hpp index ab0d87936..783daf223 100644 --- a/include/llarp.hpp +++ b/include/llarp.hpp @@ -87,6 +87,12 @@ namespace llarp bool Configure(); + bool + IsUp() const; + + bool + LooksAlive() const; + /// close async void CloseAsync(); @@ -117,9 +123,6 @@ namespace llarp bool ReloadConfig(); - void - progress(); - void setupMetrics(const MetricsConfig &metricsConfig); diff --git a/llarp/context.cpp b/llarp/context.cpp index 3e1c825e3..d85bbeedd 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -42,12 +42,6 @@ namespace llarp return logic && LogicCall(logic, f); } - void - Context::progress() - { - std::cout << "." << std::flush; - } - bool Context::Configure() { @@ -169,6 +163,18 @@ __ ___ ____ _ _ ___ _ _ ____ pidfile = fname; } + bool + Context::IsUp() const + { + return router && router->IsRunning(); + } + + bool + Context::LooksAlive() const + { + return router && router->LooksAlive(); + } + int Context::LoadDatabase() { diff --git a/llarp/router/abstractrouter.hpp b/llarp/router/abstractrouter.hpp index b23c5f4bd..17d63e34a 100644 --- a/llarp/router/abstractrouter.hpp +++ b/llarp/router/abstractrouter.hpp @@ -140,6 +140,9 @@ namespace llarp virtual bool IsRunning() const = 0; + virtual bool + LooksAlive() const = 0; + /// stop running the router logic gracefully virtual void Stop() = 0; diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 3d2438de3..6f5478959 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -60,6 +60,7 @@ namespace llarp _stopping.store(false); _running.store(false); + _lastTick = llarp::time_now_ms(); } Router::~Router() @@ -750,7 +751,9 @@ namespace llarp }); // expire paths paths.ExpirePaths(now); - } // namespace llarp + // update tick timestamp + _lastTick = llarp::time_now_ms(); + } bool Router::Sign(Signature &sig, const llarp_buffer_t &buf) const diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index e50ead41c..9e729ea42 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -222,6 +222,15 @@ namespace llarp return _hiddenServiceContext; } + llarp_time_t _lastTick = 0; + + bool + LooksAlive() const override + { + const llarp_time_t now = Now(); + return now <= _lastTick || (now - _lastTick) <= llarp_time_t{30000}; + } + using NetConfig_t = std::unordered_multimap< std::string, std::string >; /// default network config for default network interface diff --git a/llarp/util/bencode.cpp b/llarp/util/bencode.cpp index bb40b13c4..06c8ee273 100644 --- a/llarp/util/bencode.cpp +++ b/llarp/util/bencode.cpp @@ -78,14 +78,7 @@ bencode_write_bytestring(llarp_buffer_t* buff, const void* data, size_t sz) bool bencode_write_uint64(llarp_buffer_t* buff, uint64_t i) { -// NetBSDs also do this shit in long mode, wouldn't be surprised -// if all the BSDs do by default -#if !defined(__LP64__) || (__APPLE__ && __MACH__) || (__NetBSD__) \ - || (__OpenBSD__) if(!buff->writef("i%llu", i)) -#else - if(!buff->writef("i%lu", i)) -#endif { return false; }