Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 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,12 @@ 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.
if (event == ConnectionEvent::Connected && state() != State::Open) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @danzh2010 I think this will be a semantic merge conflict with your ongoing change FYI.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this change be applied to any non-close event? instead of event == ConnectionEvent::Connected, using event != ConnectionEvent::LocalClosed && event != ConnectionEvent::RemoteClosed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure happy to make that change. Either way it's pretty fragile. :(

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