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
10 changes: 8 additions & 2 deletions source/common/network/connection_impl_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ void ConnectionImplBase::initializeDelayedCloseTimer() {

void ConnectionImplBase::raiseConnectionEvent(ConnectionEvent event) {
for (ConnectionCallbacks* callback : callbacks_) {
// TODO(mattklein123): If we close while raising a connected event we should not raise further
// connected events.
// If a previous connected callback closed the connection, don't raise any further connected
// events. There was already recursion raising closed events. We still raise closed events
// to further callbacks because such events are typically used for cleanup.
if (event != ConnectionEvent::LocalClose && event != ConnectionEvent::RemoteClose &&
Comment thread
mattklein123 marked this conversation as resolved.
state() != State::Open) {
return;
}

if (callback != nullptr) {
callback->onEvent(event);
}
Expand Down
8 changes: 7 additions & 1 deletion test/common/network/connection_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,15 @@ TEST_P(ConnectionImplTest, CloseDuringConnectCallback) {
EXPECT_TRUE(client_connection_->connecting());

StrictMock<MockConnectionCallbacks> added_and_removed_callbacks;
// Make sure removed connections don't get events.
// Make sure removed callbacks don't get events.
client_connection_->addConnectionCallbacks(added_and_removed_callbacks);
client_connection_->removeConnectionCallbacks(added_and_removed_callbacks);

// Make sure later callbacks don't receive a connected event if an earlier callback closed
// the connection during its callback.
StrictMock<MockConnectionCallbacks> later_callbacks;
client_connection_->addConnectionCallbacks(later_callbacks);

std::shared_ptr<MockReadFilter> add_and_remove_filter =
std::make_shared<StrictMock<MockReadFilter>>();

Expand All @@ -346,6 +351,7 @@ TEST_P(ConnectionImplTest, CloseDuringConnectCallback) {
client_connection_->close(ConnectionCloseType::NoFlush);
}));
EXPECT_CALL(client_callbacks_, onEvent(ConnectionEvent::LocalClose));
EXPECT_CALL(later_callbacks, onEvent(ConnectionEvent::LocalClose));

read_filter_ = std::make_shared<NiceMock<MockReadFilter>>();

Expand Down