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

Side by Side Diff: net/base/host_resolver_impl.cc

Issue 7011044: Add a command line option to turn off retry attempts to resolve host (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base/host_resolver_impl.h" 5 #include "net/base/host_resolver_impl.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <Winsock2.h> 8 #include <Winsock2.h>
9 #elif defined(OS_POSIX) 9 #elif defined(OS_POSIX)
10 #include <netdb.h> 10 #include <netdb.h>
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 base::TimeDelta::FromMinutes(1), 90 base::TimeDelta::FromMinutes(1),
91 base::TimeDelta::FromSeconds(0)); // Disable caching of failed DNS. 91 base::TimeDelta::FromSeconds(0)); // Disable caching of failed DNS.
92 92
93 return cache; 93 return cache;
94 } 94 }
95 95
96 } // anonymous namespace 96 } // anonymous namespace
97 97
98 // static 98 // static
99 HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves, 99 HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves,
100 size_t max_retry_attempts,
100 NetLog* net_log) { 101 NetLog* net_log) {
101 // Maximum of 8 concurrent resolver threads. 102 // Maximum of 8 concurrent resolver threads.
102 // Some routers (or resolvers) appear to start to provide host-not-found if 103 // Some routers (or resolvers) appear to start to provide host-not-found if
103 // too many simultaneous resolutions are pending. This number needs to be 104 // too many simultaneous resolutions are pending. This number needs to be
104 // further optimized, but 8 is what FF currently does. 105 // further optimized, but 8 is what FF currently does.
105 static const size_t kDefaultMaxJobs = 8u; 106 static const size_t kDefaultMaxJobs = 8u;
106 107
107 if (max_concurrent_resolves == HostResolver::kDefaultParallelism) 108 if (max_concurrent_resolves == HostResolver::kDefaultParallelism)
108 max_concurrent_resolves = kDefaultMaxJobs; 109 max_concurrent_resolves = kDefaultMaxJobs;
109 110
111 // Maximum of 4 retry attempts for host resolution.
112 static const size_t kDefaultMaxRetryAttempts = 4u;
113
114 if (max_retry_attempts == HostResolver::kDefaultRetryAttempts)
115 max_retry_attempts = kDefaultMaxRetryAttempts;
116
110 HostResolverImpl* resolver = 117 HostResolverImpl* resolver =
111 new HostResolverImpl(NULL, CreateDefaultCache(), 118 new HostResolverImpl(NULL, CreateDefaultCache(), max_concurrent_resolves,
112 max_concurrent_resolves, net_log); 119 max_retry_attempts, net_log);
113 120
114 return resolver; 121 return resolver;
115 } 122 }
116 123
117 static int ResolveAddrInfo(HostResolverProc* resolver_proc, 124 static int ResolveAddrInfo(HostResolverProc* resolver_proc,
118 const std::string& host, 125 const std::string& host,
119 AddressFamily address_family, 126 AddressFamily address_family,
120 HostResolverFlags host_resolver_flags, 127 HostResolverFlags host_resolver_flags,
121 AddressList* out, 128 AddressList* out,
122 int* os_error) { 129 int* os_error) {
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 origin_loop_->PostTask( 437 origin_loop_->PostTask(
431 FROM_HERE, 438 FROM_HERE,
432 NewRunnableMethod(this, &Job::OnLookupComplete, AddressList(), 439 NewRunnableMethod(this, &Job::OnLookupComplete, AddressList(),
433 start_time, attempt_number_, ERR_UNEXPECTED, 0)); 440 start_time, attempt_number_, ERR_UNEXPECTED, 0));
434 return; 441 return;
435 } 442 }
436 // Post a task to check if we get the results within a given time. 443 // Post a task to check if we get the results within a given time.
437 // OnCheckForComplete has the potential for starting a new attempt on a 444 // OnCheckForComplete has the potential for starting a new attempt on a
438 // different worker thread if none of our outstanding attempts have 445 // different worker thread if none of our outstanding attempts have
439 // completed yet. 446 // completed yet.
440 origin_loop_->PostDelayedTask( 447 if (attempt_number_ <= resolver_->max_retry_attempts()) {
441 FROM_HERE, 448 origin_loop_->PostDelayedTask(
442 NewRunnableMethod(this, &Job::OnCheckForComplete), 449 FROM_HERE,
443 unresponsive_delay_.InMilliseconds()); 450 NewRunnableMethod(this, &Job::OnCheckForComplete),
451 unresponsive_delay_.InMilliseconds());
452 }
444 } 453 }
445 454
446 // Cancels the current job. The Job will be orphaned. Any outstanding resolve 455 // Cancels the current job. The Job will be orphaned. Any outstanding resolve
447 // attempts running on worker threads will continue running. Only once all the 456 // attempts running on worker threads will continue running. Only once all the
448 // attempts complete will the final reference to this Job be released. 457 // attempts complete will the final reference to this Job be released.
449 void Cancel() { 458 void Cancel() {
450 DCHECK(origin_loop_->BelongsToCurrentThread()); 459 DCHECK(origin_loop_->BelongsToCurrentThread());
451 net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL); 460 net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL);
452 461
453 HostResolver* resolver = resolver_; 462 HostResolver* resolver = resolver_;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 origin_loop_->PostTask( 542 origin_loop_->PostTask(
534 FROM_HERE, 543 FROM_HERE,
535 NewRunnableMethod(this, &Job::OnLookupComplete, results, start_time, 544 NewRunnableMethod(this, &Job::OnLookupComplete, results, start_time,
536 attempt_number, error, os_error)); 545 attempt_number, error, os_error));
537 } 546 }
538 547
539 // Callback to see if DoLookup() has finished or not (runs on origin thread). 548 // Callback to see if DoLookup() has finished or not (runs on origin thread).
540 void OnCheckForComplete() { 549 void OnCheckForComplete() {
541 DCHECK(origin_loop_->BelongsToCurrentThread()); 550 DCHECK(origin_loop_->BelongsToCurrentThread());
542 551
543 if (was_cancelled() || was_completed()) 552 if (was_completed() || was_cancelled())
544 return; 553 return;
545 554
546 DCHECK(resolver_); 555 DCHECK(resolver_);
547 base::TimeDelta unresponsive_delay = 556 unresponsive_delay_ *= resolver_->retry_factor();
548 unresponsive_delay_ * resolver_->retry_factor();
549 if (unresponsive_delay >= resolver_->maximum_unresponsive_delay())
550 return;
551
552 unresponsive_delay_ = unresponsive_delay;
553 StartLookupAttempt(); 557 StartLookupAttempt();
554 } 558 }
555 559
556 // Callback for when DoLookup() completes (runs on origin thread). 560 // Callback for when DoLookup() completes (runs on origin thread).
557 void OnLookupComplete(const AddressList& results, 561 void OnLookupComplete(const AddressList& results,
558 const base::TimeTicks& start_time, 562 const base::TimeTicks& start_time,
559 const uint32 attempt_number, 563 const uint32 attempt_number,
560 int error, 564 int error,
561 const int os_error) { 565 const int os_error) {
562 DCHECK(origin_loop_->BelongsToCurrentThread()); 566 DCHECK(origin_loop_->BelongsToCurrentThread());
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 // The requests which are waiting to be started for this pool. 1008 // The requests which are waiting to be started for this pool.
1005 PendingRequestsQueue pending_requests_[NUM_PRIORITIES]; 1009 PendingRequestsQueue pending_requests_[NUM_PRIORITIES];
1006 }; 1010 };
1007 1011
1008 //----------------------------------------------------------------------------- 1012 //-----------------------------------------------------------------------------
1009 1013
1010 HostResolverImpl::HostResolverImpl( 1014 HostResolverImpl::HostResolverImpl(
1011 HostResolverProc* resolver_proc, 1015 HostResolverProc* resolver_proc,
1012 HostCache* cache, 1016 HostCache* cache,
1013 size_t max_jobs, 1017 size_t max_jobs,
1018 size_t max_retry_attempts,
1014 NetLog* net_log) 1019 NetLog* net_log)
1015 : cache_(cache), 1020 : cache_(cache),
1016 max_jobs_(max_jobs), 1021 max_jobs_(max_jobs),
1022 max_retry_attempts_(max_retry_attempts),
1017 unresponsive_delay_(base::TimeDelta::FromMilliseconds(6000)), 1023 unresponsive_delay_(base::TimeDelta::FromMilliseconds(6000)),
1018 retry_factor_(2), 1024 retry_factor_(2),
1019 maximum_unresponsive_delay_(base::TimeDelta::FromMilliseconds(60000)),
1020 next_request_id_(0), 1025 next_request_id_(0),
1021 next_job_id_(0), 1026 next_job_id_(0),
1022 resolver_proc_(resolver_proc), 1027 resolver_proc_(resolver_proc),
1023 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), 1028 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED),
1024 shutdown_(false), 1029 shutdown_(false),
1025 ipv6_probe_monitoring_(false), 1030 ipv6_probe_monitoring_(false),
1026 additional_resolver_flags_(0), 1031 additional_resolver_flags_(0),
1027 net_log_(net_log) { 1032 net_log_(net_log) {
1028 DCHECK_GT(max_jobs, 0u); 1033 DCHECK_GT(max_jobs, 0u);
1029 1034
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 } 1513 }
1509 1514
1510 HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) { 1515 HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) {
1511 DCHECK(CanCreateJobForPool(*GetPoolForRequest(req))); 1516 DCHECK(CanCreateJobForPool(*GetPoolForRequest(req)));
1512 Key key = GetEffectiveKeyForRequest(req->info()); 1517 Key key = GetEffectiveKeyForRequest(req->info());
1513 1518
1514 req->request_net_log().AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB, 1519 req->request_net_log().AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB,
1515 NULL); 1520 NULL);
1516 1521
1517 scoped_refptr<Job> job(new Job(next_job_id_++, this, key, 1522 scoped_refptr<Job> job(new Job(next_job_id_++, this, key,
1518 req->request_net_log(), net_log_)); 1523 req->request_net_log(), net_log_));
1519 job->AddRequest(req); 1524 job->AddRequest(req);
1520 AddOutstandingJob(job); 1525 AddOutstandingJob(job);
1521 job->Start(); 1526 job->Start();
1522 1527
1523 return job.get(); 1528 return job.get();
1524 } 1529 }
1525 1530
1526 int HostResolverImpl::EnqueueRequest(JobPool* pool, Request* req) { 1531 int HostResolverImpl::EnqueueRequest(JobPool* pool, Request* req) {
1527 scoped_ptr<Request> req_evicted_from_queue( 1532 scoped_ptr<Request> req_evicted_from_queue(
1528 pool->InsertPendingRequest(req)); 1533 pool->InsertPendingRequest(req));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; 1584 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY;
1580 } else { 1585 } else {
1581 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; 1586 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY;
1582 } 1587 }
1583 #endif 1588 #endif
1584 AbortAllInProgressJobs(); 1589 AbortAllInProgressJobs();
1585 // |this| may be deleted inside AbortAllInProgressJobs(). 1590 // |this| may be deleted inside AbortAllInProgressJobs().
1586 } 1591 }
1587 1592
1588 } // namespace net 1593 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698