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

Side by Side Diff: net/http/http_server_properties_impl.cc

Issue 2464263003: Limit exponential backoff for broken alternative services. (Closed)
Patch Set: Clarify comment. Created 4 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/http/http_server_properties_impl.h" 5 #include "net/http/http_server_properties_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 21
22 namespace net { 22 namespace net {
23 23
24 namespace { 24 namespace {
25 25
26 // Initial delay for broken alternative services.
26 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300; 27 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300;
28 // Subsequent failures result in exponential (base 2) backoff.
29 // Limit binary shift to limit delay to approximately 2 days.
30 const int kBrokenDelayMaxShift = 9;
27 31
28 } // namespace 32 } // namespace
29 33
30 HttpServerPropertiesImpl::HttpServerPropertiesImpl() 34 HttpServerPropertiesImpl::HttpServerPropertiesImpl()
31 : spdy_servers_map_(SpdyServersMap::NO_AUTO_EVICT), 35 : spdy_servers_map_(SpdyServersMap::NO_AUTO_EVICT),
32 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT), 36 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT),
33 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), 37 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT),
34 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT), 38 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT),
35 quic_server_info_map_(QuicServerInfoMap::NO_AUTO_EVICT), 39 quic_server_info_map_(QuicServerInfoMap::NO_AUTO_EVICT),
36 max_server_configs_stored_in_properties_(kMaxQuicServersToPersist), 40 max_server_configs_stored_in_properties_(kMaxQuicServersToPersist),
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 } 469 }
466 470
467 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( 471 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken(
468 const AlternativeService& alternative_service) { 472 const AlternativeService& alternative_service) {
469 // Empty host means use host of origin, callers are supposed to substitute. 473 // Empty host means use host of origin, callers are supposed to substitute.
470 DCHECK(!alternative_service.host.empty()); 474 DCHECK(!alternative_service.host.empty());
471 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { 475 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) {
472 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; 476 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken.";
473 return; 477 return;
474 } 478 }
475 int count = ++recently_broken_alternative_services_[alternative_service]; 479 ++recently_broken_alternative_services_[alternative_service];
480 int shift = recently_broken_alternative_services_[alternative_service] - 1;
481 if (shift > kBrokenDelayMaxShift)
482 shift = kBrokenDelayMaxShift;
476 base::TimeDelta delay = 483 base::TimeDelta delay =
477 base::TimeDelta::FromSeconds(kBrokenAlternativeProtocolDelaySecs); 484 base::TimeDelta::FromSeconds(kBrokenAlternativeProtocolDelaySecs);
478 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); 485 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << shift);
479 auto result = broken_alternative_services_.insert( 486 auto result = broken_alternative_services_.insert(
480 std::make_pair(alternative_service, when)); 487 std::make_pair(alternative_service, when));
481 // Return if alternative service is already in expiration queue. 488 // Return if alternative service is already in expiration queue.
482 if (!result.second) { 489 if (!result.second) {
483 return; 490 return;
484 } 491 }
485 492
486 // If this is the only entry in the list, schedule an expiration task. 493 // If this is the only entry in the list, schedule an expiration task.
487 // Otherwise it will be rescheduled automatically when the pending task runs. 494 // Otherwise it will be rescheduled automatically when the pending task runs.
488 if (broken_alternative_services_.size() == 1) { 495 if (broken_alternative_services_.size() == 1) {
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); 806 base::TimeDelta delay = when > now ? when - now : base::TimeDelta();
800 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 807 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
801 FROM_HERE, 808 FROM_HERE,
802 base::Bind( 809 base::Bind(
803 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, 810 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings,
804 weak_ptr_factory_.GetWeakPtr()), 811 weak_ptr_factory_.GetWeakPtr()),
805 delay); 812 delay);
806 } 813 }
807 814
808 } // namespace net 815 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698