Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: net/quic/quic_stream_factory.cc

Issue 1208933004: QUIC - disable QUIC under recent pathological connection errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move dead code out of OnHandshakeConfirmed to where it will actually work (spotted by Ryan). Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_stream_factory.h" 5 #include "net/quic/quic_stream_factory.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 bool enable_port_selection, 563 bool enable_port_selection,
564 bool always_require_handshake_confirmation, 564 bool always_require_handshake_confirmation,
565 bool disable_connection_pooling, 565 bool disable_connection_pooling,
566 float load_server_info_timeout_srtt_multiplier, 566 float load_server_info_timeout_srtt_multiplier,
567 bool enable_connection_racing, 567 bool enable_connection_racing,
568 bool enable_non_blocking_io, 568 bool enable_non_blocking_io,
569 bool disable_disk_cache, 569 bool disable_disk_cache,
570 bool prefer_aes, 570 bool prefer_aes,
571 int max_number_of_lossy_connections, 571 int max_number_of_lossy_connections,
572 float packet_loss_threshold, 572 float packet_loss_threshold,
573 int max_disabled_reasons,
574 int threshold_public_resets_post_handshake,
575 int threshold_timeouts_with_open_streams,
573 int socket_receive_buffer_size, 576 int socket_receive_buffer_size,
574 const QuicTagVector& connection_options) 577 const QuicTagVector& connection_options)
575 : require_confirmation_(true), 578 : require_confirmation_(true),
576 host_resolver_(host_resolver), 579 host_resolver_(host_resolver),
577 client_socket_factory_(client_socket_factory), 580 client_socket_factory_(client_socket_factory),
578 http_server_properties_(http_server_properties), 581 http_server_properties_(http_server_properties),
579 transport_security_state_(transport_security_state), 582 transport_security_state_(transport_security_state),
580 quic_server_info_factory_(nullptr), 583 quic_server_info_factory_(nullptr),
581 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), 584 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory),
582 random_generator_(random_generator), 585 random_generator_(random_generator),
583 clock_(clock), 586 clock_(clock),
584 max_packet_length_(max_packet_length), 587 max_packet_length_(max_packet_length),
585 config_(InitializeQuicConfig(connection_options)), 588 config_(InitializeQuicConfig(connection_options)),
586 supported_versions_(supported_versions), 589 supported_versions_(supported_versions),
587 enable_port_selection_(enable_port_selection), 590 enable_port_selection_(enable_port_selection),
588 always_require_handshake_confirmation_( 591 always_require_handshake_confirmation_(
589 always_require_handshake_confirmation), 592 always_require_handshake_confirmation),
590 disable_connection_pooling_(disable_connection_pooling), 593 disable_connection_pooling_(disable_connection_pooling),
591 load_server_info_timeout_srtt_multiplier_( 594 load_server_info_timeout_srtt_multiplier_(
592 load_server_info_timeout_srtt_multiplier), 595 load_server_info_timeout_srtt_multiplier),
593 enable_connection_racing_(enable_connection_racing), 596 enable_connection_racing_(enable_connection_racing),
594 enable_non_blocking_io_(enable_non_blocking_io), 597 enable_non_blocking_io_(enable_non_blocking_io),
595 disable_disk_cache_(disable_disk_cache), 598 disable_disk_cache_(disable_disk_cache),
596 prefer_aes_(prefer_aes), 599 prefer_aes_(prefer_aes),
597 max_number_of_lossy_connections_(max_number_of_lossy_connections), 600 max_number_of_lossy_connections_(max_number_of_lossy_connections),
598 packet_loss_threshold_(packet_loss_threshold), 601 packet_loss_threshold_(packet_loss_threshold),
602 max_disabled_reasons_(max_disabled_reasons),
603 num_public_resets_post_handshake_(0),
604 num_timeouts_with_open_streams_(0),
605 max_public_resets_post_handshake_(0),
606 max_timeouts_with_open_streams_(0),
607 threshold_timeouts_with_open_streams_(
608 threshold_timeouts_with_open_streams),
609 threshold_public_resets_post_handshake_(
610 threshold_public_resets_post_handshake),
599 socket_receive_buffer_size_(socket_receive_buffer_size), 611 socket_receive_buffer_size_(socket_receive_buffer_size),
600 port_seed_(random_generator_->RandUint64()), 612 port_seed_(random_generator_->RandUint64()),
601 check_persisted_supports_quic_(true), 613 check_persisted_supports_quic_(true),
602 task_runner_(nullptr), 614 task_runner_(nullptr),
603 weak_factory_(this) { 615 weak_factory_(this) {
604 DCHECK(transport_security_state_); 616 DCHECK(transport_security_state_);
605 crypto_config_.set_user_agent_id(user_agent_id); 617 crypto_config_.set_user_agent_id(user_agent_id);
606 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); 618 crypto_config_.AddCanonicalSuffix(".c.youtube.com");
607 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); 619 crypto_config_.AddCanonicalSuffix(".googlevideo.com");
608 crypto_config_.AddCanonicalSuffix(".googleusercontent.com"); 620 crypto_config_.AddCanonicalSuffix(".googleusercontent.com");
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 STLDeleteElements(&(active_jobs_[server_id])); 835 STLDeleteElements(&(active_jobs_[server_id]));
824 active_jobs_.erase(server_id); 836 active_jobs_.erase(server_id);
825 job_requests_map_.erase(server_id); 837 job_requests_map_.erase(server_id);
826 } 838 }
827 839
828 scoped_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession( 840 scoped_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession(
829 QuicClientSession* session) { 841 QuicClientSession* session) {
830 return scoped_ptr<QuicHttpStream>(new QuicHttpStream(session->GetWeakPtr())); 842 return scoped_ptr<QuicHttpStream>(new QuicHttpStream(session->GetWeakPtr()));
831 } 843 }
832 844
845 const QuicClientSession::QuicDisabledReason
846 QuicStreamFactory::QuicDisabledReason(uint16 port) const {
847 if (max_number_of_lossy_connections_ > 0 &&
848 number_of_lossy_connections_.at(port) >=
849 max_number_of_lossy_connections_) {
850 return QuicClientSession::QUIC_DISABLED_BAD_PACKET_LOSS_RATE;
851 }
852 if (threshold_public_resets_post_handshake_ > 0 &&
853 num_public_resets_post_handshake_ >=
854 threshold_public_resets_post_handshake_) {
855 return QuicClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE;
856 }
857 if (threshold_timeouts_with_open_streams_ > 0 &&
858 num_timeouts_with_open_streams_ >=
859 threshold_timeouts_with_open_streams_) {
860 return QuicClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS;
861 }
862 return QuicClientSession::QUIC_DISABLED_NOT;
863 }
864
865 const char* QuicStreamFactory::QuicDisabledReasonString() const {
866 // TODO(ckrasic) - better solution for port/lossy connections?
867 const uint16 port = 443;
868 switch (QuicDisabledReason(port)) {
869 case QuicClientSession::QUIC_DISABLED_BAD_PACKET_LOSS_RATE:
870 return "bad packet loss rate";
Ryan Hamilton 2015/07/07 03:09:37 nit: Can you use a leading Capital and end with a
Buck 2015/07/07 18:38:48 Done.
871 case QuicClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE:
872 return "public resets after successful handshakes";
873 case QuicClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS:
874 return "connection timeouts with streams open";
875 default:
876 return "";
877 }
878 }
879
833 bool QuicStreamFactory::IsQuicDisabled(uint16 port) { 880 bool QuicStreamFactory::IsQuicDisabled(uint16 port) {
834 return max_number_of_lossy_connections_ > 0 && 881 return QuicDisabledReason(port) != QuicClientSession::QUIC_DISABLED_NOT;
835 number_of_lossy_connections_[port] >= max_number_of_lossy_connections_;
836 } 882 }
837 883
838 bool QuicStreamFactory::OnHandshakeConfirmed(QuicClientSession* session, 884 bool QuicStreamFactory::OnHandshakeConfirmed(QuicClientSession* session,
839 float packet_loss_rate) { 885 float packet_loss_rate) {
840 DCHECK(session); 886 DCHECK(session);
841 uint16 port = session->server_id().port(); 887 uint16 port = session->server_id().port();
842 if (packet_loss_rate < packet_loss_threshold_) { 888 if (packet_loss_rate < packet_loss_threshold_) {
843 number_of_lossy_connections_[port] = 0; 889 number_of_lossy_connections_[port] = 0;
844 return false; 890 return false;
845 } 891 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 const IpAliasKey ip_alias_key(session->connection()->peer_address(), 945 const IpAliasKey ip_alias_key(session->connection()->peer_address(),
900 aliases.begin()->is_https()); 946 aliases.begin()->is_https());
901 ip_aliases_[ip_alias_key].erase(session); 947 ip_aliases_[ip_alias_key].erase(session);
902 if (ip_aliases_[ip_alias_key].empty()) { 948 if (ip_aliases_[ip_alias_key].empty()) {
903 ip_aliases_.erase(ip_alias_key); 949 ip_aliases_.erase(ip_alias_key);
904 } 950 }
905 } 951 }
906 session_aliases_.erase(session); 952 session_aliases_.erase(session);
907 } 953 }
908 954
955 void QuicStreamFactory::MaybeDisableQuic(QuicClientSession* session) {
956 DCHECK(session);
957 uint16 port = session->server_id().port();
958 if (IsQuicDisabled(port))
959 return;
960
961 // Expire the oldest disabled_reason if appropriate. This enforces that we
962 // only consider the max_disabled_reasons_ most recent sessions.
963 enum QuicClientSession::QuicDisabledReason disabled_reason;
Alexei Svitkine (slow) 2015/07/07 15:15:29 Nit: No need for "enum".
Buck 2015/07/07 18:38:48 Done.
964 if (static_cast<int>(disabled_reasons_.size()) == max_disabled_reasons_) {
965 disabled_reason = disabled_reasons_.front();
966 disabled_reasons_.pop_front();
967 if (disabled_reason ==
968 QuicClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE) {
969 num_public_resets_post_handshake_--;
Alexei Svitkine (slow) 2015/07/07 15:15:29 Nit: I think --foo; and ++foo; are preferred in Ch
Buck 2015/07/07 18:38:48 Done.
970 } else if (disabled_reason ==
971 QuicClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS) {
972 num_timeouts_with_open_streams_--;
973 }
974 }
975 disabled_reason = session->disabled_reason();
976 disabled_reasons_.push_back(disabled_reason);
977 if (disabled_reason ==
978 QuicClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE) {
979 num_public_resets_post_handshake_++;
980 } else if (disabled_reason ==
981 QuicClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS) {
982 num_timeouts_with_open_streams_++;
983 }
984 if (num_timeouts_with_open_streams_ > max_timeouts_with_open_streams_) {
985 max_timeouts_with_open_streams_ = num_timeouts_with_open_streams_;
986 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.QuicStreamFactory.TimeoutsWithOpenStreams",
987 num_timeouts_with_open_streams_, 0, 20, 10);
988 }
989
990 if (num_public_resets_post_handshake_ > max_public_resets_post_handshake_) {
991 max_public_resets_post_handshake_ = num_public_resets_post_handshake_;
992 UMA_HISTOGRAM_CUSTOM_COUNTS(
993 "Net.QuicStreamFactory.PublicResetsPostHandshake",
994 num_public_resets_post_handshake_, 0, 20, 10);
995 }
996
997 if (IsQuicDisabled(port)) {
998 if (disabled_reason ==
999 QuicClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE) {
1000 session->CloseSessionOnErrorAndNotifyFactoryLater(
1001 ERR_ABORTED, QUIC_PUBLIC_RESETS_POST_HANDSHAKE);
1002 } else if (disabled_reason ==
1003 QuicClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS) {
1004 session->CloseSessionOnErrorAndNotifyFactoryLater(
1005 ERR_ABORTED, QUIC_TIMEOUTS_WITH_OPEN_STREAMS);
1006 }
1007 UMA_HISTOGRAM_ENUMERATION("Net.QuicStreamFactory.DisabledReasons",
1008 disabled_reason,
1009 QuicClientSession::QUIC_DISABLED_MAX);
1010 }
1011 }
1012
909 void QuicStreamFactory::OnSessionClosed(QuicClientSession* session) { 1013 void QuicStreamFactory::OnSessionClosed(QuicClientSession* session) {
910 DCHECK_EQ(0u, session->GetNumOpenStreams()); 1014 DCHECK_EQ(0u, session->GetNumOpenStreams());
1015 MaybeDisableQuic(session);
911 OnSessionGoingAway(session); 1016 OnSessionGoingAway(session);
912 delete session; 1017 delete session;
913 all_sessions_.erase(session); 1018 all_sessions_.erase(session);
914 } 1019 }
915 1020
916 void QuicStreamFactory::OnSessionConnectTimeout( 1021 void QuicStreamFactory::OnSessionConnectTimeout(
917 QuicClientSession* session) { 1022 QuicClientSession* session) {
918 const AliasSet& aliases = session_aliases_[session]; 1023 const AliasSet& aliases = session_aliases_[session];
919 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); 1024 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end();
920 ++it) { 1025 ++it) {
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 // Since the session was active, there's no longer an 1385 // Since the session was active, there's no longer an
1281 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP 1386 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP
1282 // job also fails. So to avoid not using QUIC when we otherwise could, we mark 1387 // job also fails. So to avoid not using QUIC when we otherwise could, we mark
1283 // it as recently broken, which means that 0-RTT will be disabled but we'll 1388 // it as recently broken, which means that 0-RTT will be disabled but we'll
1284 // still race. 1389 // still race.
1285 http_server_properties_->MarkAlternativeServiceRecentlyBroken( 1390 http_server_properties_->MarkAlternativeServiceRecentlyBroken(
1286 alternative_service); 1391 alternative_service);
1287 } 1392 }
1288 1393
1289 } // namespace net 1394 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698