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 <zstein@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24411}
This commit is contained in:
Zach Stein
2018-08-22 17:41:35 -07:00
committed by Commit Bot
parent 40de15d9a6
commit 4d92b8467c
2 changed files with 14 additions and 2 deletions

View File

@ -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;
}

View File

@ -242,6 +242,7 @@ class UDPPort : public Port {
StunRequestManager requests_;
rtc::AsyncPacketSocket* socket_;
int error_;
int send_error_count_ = 0;
std::unique_ptr<AddressResolver> resolver_;
bool ready_;
int stun_keepalive_delay_;