diff --git a/CMakeLists.txt b/CMakeLists.txt index 2527da5..5d9d845 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,9 @@ if (SOLANACEAE_SDBOT_WEBUI_STANDALONE) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") endif() +#add_compile_options(-fsanitize=undefined) +#link_libraries(-fsanitize=undefined) + # external libs add_subdirectory(./external EXCLUDE_FROM_ALL) # before increasing warn levels, sad :( diff --git a/src/sd_bot.cpp b/src/sd_bot.cpp index 1f40f7c..3511398 100644 --- a/src/sd_bot.cpp +++ b/src/sd_bot.cpp @@ -194,8 +194,8 @@ float SDBot::iterate(void) { _current_task = std::nullopt; } - if (_current_task.has_value()) { - _curr_future.reset(); + if (_curr_future.has_value()) { + _curr_future.reset(); // might block and wait } } @@ -206,8 +206,8 @@ float SDBot::iterate(void) { if (_cli == nullptr) { const std::string server_host {_conf.get_string("SDBot", "server_host").value()}; - _cli = std::make_unique(server_host, _conf.get_int("SDBot", "server_port").value()); - _cli->set_read_timeout(std::chrono::minutes(5)); + _cli = std::make_shared(server_host, _conf.get_int("SDBot", "server_port").value()); + _cli->set_read_timeout(std::chrono::minutes(2)); // because of discarding futures, it can block main for a while } nlohmann::json j_body; @@ -244,10 +244,17 @@ float SDBot::iterate(void) { try { const std::string url {_conf.get_string("SDBot", "url_txt2img").value()}; - _curr_future = std::async(std::launch::async, [this, url, body]() -> std::vector { + _curr_future = std::async(std::launch::async, [url, body, cli = _cli]() -> std::vector { + if (!static_cast(cli)) { + return {}; + } // TODO: move to endpoint - auto res = _cli->Post(url, body, "application/json"); - std::cout << "SDB http complete " << res->status << " " << res->reason << "\n"; + auto res = cli->Post(url, body, "application/json"); + if (!static_cast(res)) { + std::cerr << "SDB error: post to sd server failed!\n"; + return {}; + } + std::cerr << "SDB http complete " << res->status << " " << res->reason << "\n"; if ( res.error() != httplib::Error::Success || res->status != 200 @@ -262,7 +269,7 @@ float SDBot::iterate(void) { // cleanup _task_map.erase(_current_task.value()); _current_task = std::nullopt; - _curr_future.reset(); + _curr_future.reset(); // might block and wait } _prompt_queue.pop(); diff --git a/src/sd_bot.hpp b/src/sd_bot.hpp index d6fd888..fd78902 100644 --- a/src/sd_bot.hpp +++ b/src/sd_bot.hpp @@ -31,7 +31,7 @@ class SDBot : public RegistryMessageModelEventI { uint64_t _last_task_counter = 0; std::optional _current_task; - std::unique_ptr _cli; + std::shared_ptr _cli; std::optional>> _curr_future; std::default_random_engine _rng;