Skip to content

Commit

Permalink
Migrate back to the default network after handshake has been confirme…
Browse files Browse the repository at this point in the history
…d and the connection is originally created on the non-default network.

Bug: 790547
Change-Id: Ia991d49e5c8197fca0a98224239e1bc412ca9005
Reviewed-on: https://chromium-review.googlesource.com/1176656
Commit-Queue: Zhongyi Shi <zhongyi@chromium.org>
Reviewed-by: Ryan Hamilton <rch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583868}
  • Loading branch information
zyshi authored and Commit Bot committed Aug 16, 2018
1 parent b070be8 commit f3fcbbe
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
10 changes: 9 additions & 1 deletion net/quic/quic_chromium_client_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,15 @@ void QuicChromiumClientSession::OnCryptoHandshakeEvent(
}

NotifyRequestsOfConfirmation(OK);
// TODO(zhongyi): spin up the timer to migrate back to the default network.
// Attempt to migrate back to the default network after handshake has been
// confirmed if the session is not created on the default network.
if (migrate_session_on_network_change_v2_ &&
default_network_ != NetworkChangeNotifier::kInvalidNetworkHandle &&
GetDefaultSocket()->GetBoundNetwork() != default_network_) {
current_connection_migration_cause_ = ON_MIGRATE_BACK_TO_DEFAULT_NETWORK;
StartMigrateBackToDefaultNetworkTimer(
base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs));
}
}
quic::QuicSpdySession::OnCryptoHandshakeEvent(event);
}
Expand Down
45 changes: 44 additions & 1 deletion net/quic/quic_stream_factory_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4804,6 +4804,18 @@ TEST_P(QuicStreamFactoryTest, NewConnectionAfterHandshakeTimeout) {
quic::QUIC_HANDSHAKE_TIMEOUT);
}

// Sets up a test to verify that a new connection will be created on the
// alternate network after the initial connection fails before handshake with
// signals delivered in the following order (alternate network is available):
// - the default network is not able to complete crypto handshake;
// - the original connection is closed with |quic_error|;
// - a new connection is created on the alternate network and is able to finish
// crypto handshake;
// - the new session on the alternate network attempts to migrate back to the
// default network by sending probes;
// - default network being disconnected is delivered: session will stop probing
// the original network.
// - alternate network is made by default.
void QuicStreamFactoryTestBase::
TestNewConnectionOnAlternateNetworkBeforeHandshake(
quic::QuicErrorCode quic_error) {
Expand Down Expand Up @@ -4844,10 +4856,17 @@ void QuicStreamFactoryTestBase::
socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING);
socket_data2.AddWrite(SYNCHRONOUS,
client_maker_.MakeAckAndRstPacket(
4, false, GetNthClientInitiatedStreamId(0),
5, false, GetNthClientInitiatedStreamId(0),
quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true));
socket_data2.AddSocketDataToFactory(socket_factory_.get());

// Socket data for probing on the default network.
MockQuicData probing_data;
probing_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read.
probing_data.AddWrite(SYNCHRONOUS,
client_maker_.MakeConnectivityProbingPacket(4, false));
probing_data.AddSocketDataToFactory(socket_factory_.get());

// Create request and QuicHttpStream.
QuicStreamRequest request(factory_.get());
EXPECT_EQ(ERR_IO_PENDING,
Expand Down Expand Up @@ -4913,6 +4932,30 @@ void QuicStreamFactoryTestBase::
EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback()));
EXPECT_EQ(200, response.headers->response_code());

// There should be a new task posted to migrate back to the default network.
EXPECT_EQ(1u, task_runner->GetPendingTaskCount());
base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay();
EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs),
next_task_delay);
task_runner->FastForwardBy(next_task_delay);

// There should be two tasks posted. One will retry probing and the other
// will retry migrate back.
EXPECT_EQ(2u, task_runner->GetPendingTaskCount());
next_task_delay = task_runner->NextPendingTaskDelay();
EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs),
next_task_delay);

// Deliver the signal that the default network is disconnected.
scoped_mock_network_change_notifier_->mock_network_change_notifier()
->NotifyNetworkDisconnected(kDefaultNetworkForTests);
// Verify no connectivity probes will be sent as probing will be cancelled.
task_runner->FastForwardUntilNoTasksRemain();
// Deliver the signal that the alternate network is made default.
scoped_mock_network_change_notifier_->mock_network_change_notifier()
->NotifyNetworkMadeDefault(kNewNetworkForTests);
EXPECT_EQ(0u, task_runner->GetPendingTaskCount());

stream.reset();
EXPECT_TRUE(socket_data.AllReadDataConsumed());
EXPECT_TRUE(socket_data.AllWriteDataConsumed());
Expand Down

0 comments on commit f3fcbbe

Please sign in to comment.