Phase C: run RPC per-client handlers on a Void ThreadPool

Replace the one-detached-std::thread-per-client model and its manual
bookkeeping (the clientThreads_ vector, finished-thread sweep, and
detach-after-timeout shutdown) with a Void::Concurrency::ThreadPool:

- start() builds clientPool_ (CLIENT_POOL_SIZE workers); the accept loop
  submits each accepted connection's handleClient + cleanup as a task.
- stop() closes the client sockets (so each handler's read() returns) then
  resets the pool, whose destructor drains and joins every handler.

The accept loop stays on its own dedicated thread — a long-lived listen
loop is not pool work, and its cancellable/timeout-guarded shutdown is
unchanged. CLIENT_POOL_SIZE (64) caps concurrent long-lived client handlers
far above any realistic count for this bot's RPC surface.

Build green. Runtime behavior (live RPC sessions) is unverified here.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-23 13:26:16 +03:00
1 parent ef094c0d78
commit 3af9aecbec
2 files changed
+32 -54

No files matched your search

+9 -3
View File
@@ -4,10 +4,12 @@
#include <RpcTypes.hpp>
#include <TrackTypes.hpp>
#include <Types.hpp>
#include <Void/Async/ThreadPool.hpp>
#include <boost/asio.hpp>
#include <boost/beast.hpp>
#include <boost/beast/websocket.hpp>
#include <functional>
#include <memory>
#include <mutex>
#include <set>
#include <thread>
@@ -81,9 +83,13 @@ namespace Echoion::Core
std::mutex clientsMutex_;
std::atomic<uint64_t> nextClientId_{1};
// Client threads (for proper cleanup)
std::vector<std::thread> clientThreads_;
std::mutex clientThreadsMutex_;
// Per-client handlers run on a Void worker pool instead of one
// detached std::thread each; ~ThreadPool drains and joins them on
// stop. Sized well above any realistic concurrent-client count
// (each long-lived handler holds a worker for the connection's
// lifetime).
static constexpr std::size_t CLIENT_POOL_SIZE = 64;
std::unique_ptr<Void::Concurrency::ThreadPool> clientPool_;
// Authenticated clients
std::set<uint64_t> authenticatedClients_;