Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network: fix double close event #236

Merged
merged 2 commits into from
Nov 20, 2016
Merged
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
11 changes: 9 additions & 2 deletions source/common/network/connection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ void ConnectionImpl::readDisable(bool disable) {

void ConnectionImpl::raiseEvents(uint32_t events) {
for (ConnectionCallbacks* callback : callbacks_) {
// TODO: If we close while raising a connected event we should not raise further connected
// events.
callback->onEvent(events);
}
}
Expand Down Expand Up @@ -331,8 +333,13 @@ void ConnectionImpl::onWriteReady() {
}

if (doWriteToSocket() == PostIoAction::Close) {
closeSocket();
raiseEvents(ConnectionEvent::RemoteClose);
// It is possible (though unlikely) for the connection to have already been closed during the
// write callback. This can happen if we manage to complete the SSL handshake in the write
// callback, raise a connected event, and close the connection.
if (fd_ != -1) {
closeSocket();
raiseEvents(ConnectionEvent::RemoteClose);
}
} else if ((state_ & InternalState::CloseWithFlush) && write_buffer_.length() == 0) {
conn_log_debug("write flush complete", *this);
doLocalClose();
Expand Down