Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,9 @@ BUCKAROO_DEPS
# Vim
*.swp
*.swo

# clangd
.cache/

# Claude Code
.claude/settings.local.json
8 changes: 5 additions & 3 deletions timeplus/client_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ ClientPool::ClientPtr ClientPool::Acquire(int64_t timeout_ms) {
}

void ClientPool::GuardedClient::TestConnection() noexcept {
if (!client) {
valid = false;
return;
}

try {
client->Ping();
valid = true;
} catch (...) {
valid = false;
}

TRACE("test connection: host=%s port=%d valid=%s", client->GetCurrentEndpoint()->host.c_str(), client->GetCurrentEndpoint()->port,
valid ? "true" : "false");
}

} // namespace timeplus
2 changes: 1 addition & 1 deletion timeplus/client_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ClientPool {

GuardedClient& operator=(GuardedClient&& other) noexcept {
if (this != &other) {
if (pool_ && client) {
if (pool_) {
pool_->Release(std::move(client), valid);
}
pool_ = other.pool_;
Expand Down
15 changes: 15 additions & 0 deletions ut/client_pool_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,18 @@ TEST(ClientPool, BadHost) {

ASSERT_THROW(pool.Acquire(1000), std::system_error);
}

TEST(ClientPool, GuardedClientResetStillReturnsSlot) {
ClientOptions client_options;
client_options.host = "localhost";
ClientPool pool{client_options, /*pool_size=*/1};

{
auto guarded = pool.GetGuardedClient(1000);
ASSERT_NE(guarded.client, nullptr);
guarded.client.reset();
}

auto client = pool.Acquire(100);
ASSERT_NE(client, nullptr);
}
Loading