Index: net/quic/chromium/quic_chromium_client_session.cc |
diff --git a/net/quic/chromium/quic_chromium_client_session.cc b/net/quic/chromium/quic_chromium_client_session.cc |
index c2bdf2b1df8f3b622d829ceb9a7f644fbf9fe9f5..6c86dc273f23184d9d9238cd99fba2c31da7fdd0 100644 |
--- a/net/quic/chromium/quic_chromium_client_session.cc |
+++ b/net/quic/chromium/quic_chromium_client_session.cc |
@@ -57,6 +57,10 @@ const size_t kMaxReadersPerQuicSession = 5; |
// SSLClientSocketImpl. |
const size_t kTokenBindingSignatureMapSize = 10; |
+// Time to wait (in seconds) when no networks are available and |
+// migrating sessions need to wait for a new network to connect. |
+const size_t kWaitTimeForNewNetworkSecs = 10; |
+ |
// Histograms for tracking down the crashes from http://crbug.com/354669 |
// Note: these values must be kept in sync with the corresponding values in: |
// tools/metrics/histograms/histograms.xml |
@@ -242,6 +246,7 @@ QuicChromiumClientSession::QuicChromiumClientSession( |
streams_pushed_count_(0), |
streams_pushed_and_claimed_count_(0), |
migration_pending_(false), |
+ migration_alarm_pending_(false), |
weak_factory_(this) { |
sockets_.push_back(std::move(socket)); |
packet_readers_.push_back(base::MakeUnique<QuicChromiumPacketReader>( |
@@ -1000,9 +1005,16 @@ void QuicChromiumClientSession::MigrateSessionOnWriteError() { |
if (!migration_pending_) |
return; |
Ryan Hamilton
2016/09/13 02:57:31
What happened to all the vertical white space? I f
Jana
2016/09/13 03:12:14
I wasn't sure if it was too much white space, so I
|
- if (stream_factory_ != nullptr && |
- stream_factory_->MaybeMigrateSingleSession(this, WRITE_ERROR) == |
- MigrationResult::SUCCESS) { |
+ MigrationResult result = MigrationResult::FAILURE; |
+ if (stream_factory_ != nullptr) { |
+ result = stream_factory_->MaybeMigrateSingleSession(this, WRITE_ERROR); |
+ } |
+ |
+ if (result == MigrationResult::SUCCESS) |
+ return; |
+ |
+ if (result == MigrationResult::NO_NEW_NETWORK) { |
+ OnNoNewNetwork(); |
return; |
} |
@@ -1013,6 +1025,25 @@ void QuicChromiumClientSession::MigrateSessionOnWriteError() { |
ConnectionCloseBehavior::SILENT_CLOSE); |
} |
+void QuicChromiumClientSession::OnNoNewNetwork() { |
+ if (migration_alarm_pending_) |
+ return; |
+ migration_alarm_pending_ = true; |
+ // When called from a network notification, migration_pending_ must |
+ // be set to true here. |
Ryan Hamilton
2016/09/13 00:33:18
I don't understand this comment. Perhaps you can e
Jana
2016/09/13 01:12:19
Comment changed PTAL.
|
+ migration_pending_ = true; |
+ |
+ // Block the packet writer to avoid any writes while migration is in progress. |
+ static_cast<QuicChromiumPacketWriter*>(connection()->writer()) |
+ ->set_write_blocked(true); |
+ |
+ // Post a task to maybe close the session if the alarm fires. |
+ task_runner_->PostDelayedTask( |
+ FROM_HERE, base::Bind(&QuicChromiumClientSession::OnMigrationTimeout, |
+ weak_factory_.GetWeakPtr()), |
+ base::TimeDelta::FromSeconds(kWaitTimeForNewNetworkSecs)); |
+} |
+ |
void QuicChromiumClientSession::WriteToNewSocket() { |
// Prevent any pending migration from executing. |
migration_pending_ = false; |
@@ -1050,6 +1081,39 @@ void QuicChromiumClientSession::WriteToNewSocket() { |
connection()->OnCanWrite(); |
} |
+void QuicChromiumClientSession::OnMigrationTimeout() { |
+ DLOG(INFO) << "In OnMigrationTimeout: migration_pending_: " << migration_pending_; |
Ryan Hamilton
2016/09/13 00:33:18
nit: remove this?
Jana
2016/09/13 01:12:19
Done.
|
+ if (!migration_pending_) |
Ryan Hamilton
2016/09/13 00:33:18
As discussed, if two migrations start before the f
Jana
2016/09/13 01:12:18
Changed to using sockets_.size().
|
+ return; |
+ migration_alarm_pending_ = false; |
+ migration_pending_ = false; |
Ryan Hamilton
2016/09/13 00:33:18
Since the connection is about to be deleted, I sus
Jana
2016/09/13 01:12:18
Yup, removed.
|
+ /* |
+ UMA_HISTOGRAM_ENUMERATION( |
+ "Net.QuicSession.ConnectionMigration", |
+ static_cast<int>(MigrationStatus::NO_ALTERNATE_NETWORK), |
+ static_cast<int>(MigrationStatus::MAX)); |
+ */ |
Ryan Hamilton
2016/09/13 00:33:18
What's up with this?
Jana
2016/09/13 01:12:18
Fixed.
|
+ CloseSessionOnError(ERR_NETWORK_CHANGED, |
+ QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK); |
+} |
+ |
+void QuicChromiumClientSession::OnNetworkConnected( |
+ NetworkChangeNotifier::NetworkHandle network, |
+ const BoundNetLog& bound_net_log) { |
+ // Cancel migration alarm if one is pending. |
+ migration_alarm_pending_ = false; |
+ // If migration_pending_ is false, there was no migration pending or |
+ // an earlier task completed migration. |
+ if (!migration_pending_) |
+ return; |
+ // TODO(jri): Ensure that OnSessionGoingAway is called consistently, |
+ // and that it's always called at the same time in the whole |
+ // migration process. Allows tests to be more uniform. |
+ stream_factory_->OnSessionGoingAway(this); |
+ stream_factory_->MigrateSessionToNewNetwork( |
+ this, network, /*close_session_on_error=*/true, net_log_); |
+} |
+ |
void QuicChromiumClientSession::OnWriteError(int error_code) { |
DCHECK_NE(ERR_IO_PENDING, error_code); |
DCHECK_GT(0, error_code); |