Skip to content

Commit

Permalink
AsyncConnection: close socket ASAP for standby connection
Browse files Browse the repository at this point in the history
If we have lots of connection standby, it may cause lots of fd leak.

Signed-off-by: Haomai Wang <[email protected]>
  • Loading branch information
yuyuyu101 committed Feb 11, 2015
1 parent 86f50a5 commit 7cc109a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/msg/async/AsyncConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ void AsyncConnection::process()

case STATE_CLOSED:
{
if (sd > 0)
if (sd >= 0)
center->delete_file_event(sd, EVENT_READABLE);
ldout(async_msgr->cct, 20) << __func__ << " socket closed" << dendl;
break;
Expand Down Expand Up @@ -1723,7 +1723,7 @@ int AsyncConnection::handle_connect_msg(ceph_msg_connect &connect, bufferlist &a
// Now existing connection will be alive and the current connection will
// exchange socket with existing connection because we want to maintain
// original "connection_state"
if (existing->sd > 0)
if (existing->sd >= 0)
existing->center->delete_file_event(existing->sd, EVENT_READABLE|EVENT_WRITABLE);
center->delete_file_event(sd, EVENT_READABLE|EVENT_WRITABLE);
existing->center->create_file_event(sd, EVENT_READABLE, existing->read_handler);
Expand Down Expand Up @@ -1913,7 +1913,7 @@ int AsyncConnection::send_message(Message *m)
ldout(async_msgr->cct, 10) << __func__ << " state is " << get_state_name(state)
<< " policy.server is false" << dendl;
_connect();
} else if (sd > 0 && !open_write) {
} else if (sd >= 0 && !open_write) {
center->dispatch_event_external(write_handler);
}
}
Expand Down Expand Up @@ -2012,6 +2012,8 @@ void AsyncConnection::fault()
if (sd >= 0) {
shutdown_socket();
center->delete_file_event(sd, EVENT_READABLE|EVENT_WRITABLE);
::close(sd);
sd = -1;
}
open_write = false;

Expand Down Expand Up @@ -2076,7 +2078,7 @@ void AsyncConnection::_stop()
{
assert(lock.is_locked());
ldout(async_msgr->cct, 10) << __func__ << dendl;
if (sd > 0)
if (sd >= 0)
center->delete_file_event(sd, EVENT_READABLE|EVENT_WRITABLE);

discard_out_queue();
Expand All @@ -2092,11 +2094,12 @@ void AsyncConnection::_stop()
}

state = STATE_CLOSED;
shutdown_socket();
open_write = false;
state_offset = 0;
if (sd > 0)
if (sd >= 0) {
shutdown_socket();
::close(sd);
}
sd = -1;
for (set<uint64_t>::iterator it = register_time_events.begin();
it != register_time_events.end(); ++it)
Expand Down

0 comments on commit 7cc109a

Please sign in to comment.