Skip to content

Commit

Permalink
Fix seg fault on overloaded connection (CPP-167)
Browse files Browse the repository at this point in the history
Improper static cast and use of pointer in timeout callback
Also removed unused parameter in Pool::maybe_notify_ready()
  • Loading branch information
aholmberg committed Sep 25, 2014
1 parent b8d918d commit 3f3c036
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void Pool::connect() {
spawn_connection();
}
state_ = POOL_STATE_CONNECTING;
maybe_notify_ready();
}
}

Expand Down Expand Up @@ -137,7 +138,7 @@ void Pool::defunct() {
close();
}

void Pool::maybe_notify_ready(Connection* connection) {
void Pool::maybe_notify_ready() {
// This will notify ready even if all the connections fail.
// it is up to the holder to inspect state
if (state_ == POOL_STATE_CONNECTING && connections_pending_.empty()) {
Expand Down Expand Up @@ -201,7 +202,7 @@ Connection* Pool::find_least_busy() {

void Pool::on_connection_ready(Connection* connection) {
connections_pending_.erase(connection);
maybe_notify_ready(connection);
maybe_notify_ready();

connections_.push_back(connection);
return_connection(connection);
Expand All @@ -225,12 +226,12 @@ void Pool::on_connection_closed(Connection* connection) {
defunct();
}

maybe_notify_ready(connection);
maybe_notify_ready();
maybe_close();
}

void Pool::on_pending_request_timeout(void* data) {
RequestHandler* request_handler = static_cast<RequestHandler*>(data);
void Pool::on_pending_request_timeout(RequestTimer* timer) {
RequestHandler* request_handler = static_cast<RequestHandler*>(timer->data());
pending_requests_.remove(request_handler);
request_handler->retry(RETRY_WITH_NEXT_HOST);
maybe_close();
Expand Down
4 changes: 2 additions & 2 deletions src/pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ class Pool : public RefCounted<Pool> {

private:
void defunct();
void maybe_notify_ready(Connection* connection);
void maybe_notify_ready();
void maybe_close();
void spawn_connection();
void maybe_spawn_connection();

void on_connection_ready(Connection* connection);
void on_connection_closed(Connection* connection);
void on_pending_request_timeout(void* data);
void on_pending_request_timeout(RequestTimer* data);

Connection* find_least_busy();

Expand Down

0 comments on commit 3f3c036

Please sign in to comment.