mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-29 04:03:45 +00:00
Leave pool room for UDP sessions that are still closing
An evicted session keeps its pool slot until its socket's close callback runs, so with pool capacity equal to the table's the acquire after an eviction failed: a full table dropped new-session packets after evicting a live session for nothing. The AEAD-2022 shared-session pool had the same problem with entries still referenced by relay sessions.
This commit is contained in:
+7
-2
@@ -290,11 +290,16 @@ Status UdpRelay::init(event::Loop &loop, Method &method, const UdpConfig &config
|
||||
config_ = config;
|
||||
std::uint64_t seed = 0;
|
||||
randombytes_buf(&seed, sizeof(seed));
|
||||
SS_TRY(pool_.reserve(config.max_sessions));
|
||||
// An evicted session keeps its pool slot until its socket's close
|
||||
// callback runs on a later loop iteration, so the pool needs room for
|
||||
// a table's worth of closing sessions next to the live ones.
|
||||
SS_TRY(pool_.reserve(2 * config.max_sessions));
|
||||
SS_TRY(sessions_.reserve(config.max_sessions, seed));
|
||||
if (config.kind == Kind::server) {
|
||||
if (method.psk() != nullptr) {
|
||||
SS_TRY(shared_pool_.reserve(config.max_sessions_2022));
|
||||
// An entry evicted from shared_ stays alive while a relay
|
||||
// session still references it (at most one per session).
|
||||
SS_TRY(shared_pool_.reserve(config.max_sessions_2022 + config.max_sessions));
|
||||
SS_TRY(shared_.reserve(config.max_sessions_2022, seed ^ 0x9E3779B97F4A7C15ULL));
|
||||
}
|
||||
SS_TRY(pending_.reserve(config.max_pending_dns));
|
||||
|
||||
Reference in New Issue
Block a user