From dc8001705dd0bc95c6bb7745905fc76be032aa04 Mon Sep 17 00:00:00 2001 From: Harald Alvestrand Date: Mon, 6 Jan 2020 20:01:36 +0100 Subject: [PATCH] Mark TCP connections that fail initialization as failed. This silences some spurious messages that were generated by https://chromium-review.googlesource.com/c/chromium/src/+/1986070 Bug: chromium:1038754 Change-Id: I950b82c01a7e5be1f5e910b148c0b201f814f430 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/164529 Reviewed-by: Qingsi Wang Commit-Queue: Harald Alvestrand Cr-Commit-Position: refs/heads/master@{#30156} --- p2p/base/p2p_transport_channel.cc | 3 ++- p2p/base/tcp_port.cc | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc index 781f709f06..c7cfe5a9c4 100644 --- a/p2p/base/p2p_transport_channel.cc +++ b/p2p/base/p2p_transport_channel.cc @@ -1773,7 +1773,8 @@ void P2PTransportChannel::UpdateState() { // TODO(deadbeef): Once we implement end-of-candidates signaling, // we shouldn't go from INIT to COMPLETED. RTC_DCHECK(state == IceTransportState::STATE_CONNECTING || - state == IceTransportState::STATE_COMPLETED); + state == IceTransportState::STATE_COMPLETED || + state == IceTransportState::STATE_FAILED); break; case IceTransportState::STATE_CONNECTING: RTC_DCHECK(state == IceTransportState::STATE_COMPLETED || diff --git a/p2p/base/tcp_port.cc b/p2p/base/tcp_port.cc index 6e5b8dc4a0..d1fb9b29e9 100644 --- a/p2p/base/tcp_port.cc +++ b/p2p/base/tcp_port.cc @@ -211,14 +211,24 @@ int TCPPort::SendTo(const void* data, return SOCKET_ERROR; } socket = conn->socket(); + if (!socket) { + // The failure to initialize should have been logged elsewhere, + // so this log is not important. + RTC_LOG(LS_INFO) << ToString() + << ": Attempted to send to an uninitialized socket: " + << addr.ToSensitiveString(); + error_ = EHOSTUNREACH; + return SOCKET_ERROR; + } } else { socket = GetIncoming(addr); - } - if (!socket) { - RTC_LOG(LS_ERROR) << ToString() - << ": Attempted to send to an unknown destination: " - << addr.ToSensitiveString(); - return SOCKET_ERROR; // TODO(tbd): Set error_ + if (!socket) { + RTC_LOG(LS_ERROR) << ToString() + << ": Attempted to send to an unknown destination: " + << addr.ToSensitiveString(); + error_ = EHOSTUNREACH; + return SOCKET_ERROR; + } } rtc::PacketOptions modified_options(options); CopyPortInformationToPacketInfo(&modified_options.info_signaled_after_sent); @@ -546,7 +556,6 @@ void TCPConnection::OnReadyToSend(rtc::AsyncPacketSocket* socket) { void TCPConnection::CreateOutgoingTcpSocket() { RTC_DCHECK(outgoing_); - // TODO(guoweis): Handle failures here (unlikely since TCP). int opts = (remote_candidate().protocol() == SSLTCP_PROTOCOL_NAME) ? rtc::PacketSocketFactory::OPT_TLS_FAKE : 0; @@ -567,6 +576,7 @@ void TCPConnection::CreateOutgoingTcpSocket() { } else { RTC_LOG(LS_WARNING) << ToString() << ": Failed to create connection to " << remote_candidate().address().ToSensitiveString(); + FailAndPrune(); } }