From 4d92b8467c2b77a76f3bd693a928e3a0ad0c7d04 Mon Sep 17 00:00:00 2001 From: Zach Stein Date: Wed, 22 Aug 2018 17:41:35 -0700 Subject: [PATCH] Ad-hoc rate limiting for UDPPort::SendTo failures. Bug: chromium:856088 Change-Id: I8b9edd8c7392834a7a88987963de2f8e9d37be11 Reviewed-on: https://webrtc-review.googlesource.com/93881 Commit-Queue: Zach Stein Reviewed-by: Qingsi Wang Cr-Commit-Position: refs/heads/master@{#24411} --- p2p/base/stunport.cc | 15 +++++++++++++-- p2p/base/stunport.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/p2p/base/stunport.cc b/p2p/base/stunport.cc index 9574314c76..9df3ebad29 100644 --- a/p2p/base/stunport.cc +++ b/p2p/base/stunport.cc @@ -27,6 +27,10 @@ namespace cricket { // TODO(?): Move these to a common place (used in relayport too) const int RETRY_TIMEOUT = 50 * 1000; // 50 seconds +// Stop logging errors in UDPPort::SendTo after we have logged +// |kSendErrorLogLimit| messages. Start again after a successful send. +const int kSendErrorLogLimit = 5; + // Handles a binding request sent to the STUN server. class StunBindingRequest : public StunRequest { public: @@ -270,8 +274,15 @@ int UDPPort::SendTo(const void* data, int sent = socket_->SendTo(data, size, addr, modified_options); if (sent < 0) { error_ = socket_->GetError(); - RTC_LOG(LS_ERROR) << ToString() << ": UDP send of " << size - << " bytes failed with error " << error_; + // Rate limiting added for crbug.com/856088. + // TODO(webrtc:9622): Use general rate limiting mechanism once it exists. + if (send_error_count_ < kSendErrorLogLimit) { + ++send_error_count_; + RTC_LOG(LS_ERROR) << ToString() << ": UDP send of " << size + << " bytes failed with error " << error_; + } + } else { + send_error_count_ = 0; } return sent; } diff --git a/p2p/base/stunport.h b/p2p/base/stunport.h index 9cb479df0e..76647e8eda 100644 --- a/p2p/base/stunport.h +++ b/p2p/base/stunport.h @@ -242,6 +242,7 @@ class UDPPort : public Port { StunRequestManager requests_; rtc::AsyncPacketSocket* socket_; int error_; + int send_error_count_ = 0; std::unique_ptr resolver_; bool ready_; int stun_keepalive_delay_;